Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need C# help about Classes
New Posts  All Forums:Forum Nav:

Need C# help about Classes - Page 2

post #11 of 15
Thread Starter 
Quote:
Originally Posted by {Unregistered} View Post

The variables and the getter methods seem fine but you are using your setter methods incorrectly.
The setter methods are supposed to store the values of the properties (variables) of the objects, not print them out (because that's what you have the getter methods for).
Basically, when you create an object, it is initialised with the default values for each data-type (null for String, 0 for int, 0.00 for double). The variables hold different values for each object created and initialised.
The getter methods are used to retrieve those properties of the object. (Remember they may be different for each object)
The setter methods are used to set the value of those properties of the object. They DO NOT need to print out anything. All they have to do is set the values you give to the variables of the object (they together make up the state of the object).
I have, therefore, edited the setter methods for you (I let the print instructions stay but they are basically unnecessary, and do not make up their conventional use either).
I hope you do understand the concept of Object-oriented programming in which different objects have different values in the same fields.
If you do not, I can explain them to you if you want to.

Please elaborate... Any knowledge you can throw my way is helpful

Today I also have to add this wrinkle into my code... I do not even know where to begin

First Assignment: ON TOP
Added a Wrinkle: ON BOTTOM

236
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #12 of 15
Thread Starter 
Any ideas?
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #13 of 15
Code:

public class Csharp
{

type variablename;

//Constructor
public Csharp(type invariablename)
{
variablename = invariablename;
}

//Getter
public getVar()
{
// When you call this function it will return the variables information to where you called this.
// This is  useful if you have a lot of private date, not so much for public information.
return variablename;
}

//Setter
public setVar(type invariablename)
{
variablename = invariablename;
}


};

This is pretty much the simplest I can make a class.

In the main program class you'd create a new instance of this
Code:
Csharp instancename = new Csharp(/*Any Variables that need to be passed in */)'

Then you'd call things in your code lick
Code:
instancename.getVar();
instancename.setVar(/* pass in correct type */);

The reason it is highlight pass and in is because some code languages use those as key words.
Edited by Twinnuke - 3/9/12 at 5:36am
Unto The Void
(16 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 6800k Gigabyte G1 X99-Phoenix SLI Gigabyte GTX 1080 G1 32GB RipJaw 4 DDR4-3000 
Hard DriveHard DriveHard DriveHard Drive
Samsung 850 500GB Crucial M4 2 x Spinpoint F1 Samsung 850 1TB 
CoolingOSMonitorMonitor
Noctua NH-D15S Windows 10 LG Ultrawide 29" Asus 24" 
KeyboardPowerCaseMouse
Logitech 810 EVGA P2 650 Watt In Win 303 Logitech G502 
  hide details  
Reply
Unto The Void
(16 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 6800k Gigabyte G1 X99-Phoenix SLI Gigabyte GTX 1080 G1 32GB RipJaw 4 DDR4-3000 
Hard DriveHard DriveHard DriveHard Drive
Samsung 850 500GB Crucial M4 2 x Spinpoint F1 Samsung 850 1TB 
CoolingOSMonitorMonitor
Noctua NH-D15S Windows 10 LG Ultrawide 29" Asus 24" 
KeyboardPowerCaseMouse
Logitech 810 EVGA P2 650 Watt In Win 303 Logitech G502 
  hide details  
Reply
post #14 of 15
Note, in C#, do not create "GetX" and "SetX" methods. C# has a feature called Properties which replace the need to do this.

So instead of those two methods you can just write
Code:
public int X {
get { return x; }
set ( x = value; }
}

Or, for shorthand if you don't need the explicit private variable...
Code:
public int X { get; set; }
Hexafun
(9 items)
 
  
CPUMotherboardGraphicsRAM
i7 8700k ASRock Fatal1ty Z370 Gaming-ITX/ac EVGA GTX 980 CORSAIR Vengeance 3733MHz 
Hard DriveCoolingOSPower
Samsung 960 Pro 2TB Corsair H100i v2 Windows 10 Pro Corsair AX850 Gold 
Case
Fractal Design Nano S 
  hide details  
Reply
Hexafun
(9 items)
 
  
CPUMotherboardGraphicsRAM
i7 8700k ASRock Fatal1ty Z370 Gaming-ITX/ac EVGA GTX 980 CORSAIR Vengeance 3733MHz 
Hard DriveCoolingOSPower
Samsung 960 Pro 2TB Corsair H100i v2 Windows 10 Pro Corsair AX850 Gold 
Case
Fractal Design Nano S 
  hide details  
Reply
post #15 of 15
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need C# help about Classes