Jump to content

C# Class Question

Go to solution Solved by spenser_l,

This line will instantiate, or create a new instance of the Box class. The Box class is like a template, with it, you can create unique Box objects that have different values for the same parameters (length, width etc.)

 

The first word "Box" is the name of the class. 

 

The second word, "Box1" is simply the name of the particular Box object that is being created. It is the name that references the Box object that is created, or instantiated with the word "new."

 

"new" in object oriented programming languages is used when you're actually creating a new instance of a class; in this case, a new Box object.

 

"Box()" is the other component for object creation. The brackets () are used for when there are arguments, or parameters for when an object is created. For example, if the Box class had variables such as length and width in the constructor, you would have to pass values into the parameters when creating a new Box object.

 

e.g. Box b1 = new Box(3, 4);

 

This may seem confusing at first. If it is, I recommend reading up more about object oriented concepts in general to get a better grasp as to what you are doing.

Greetings friends, i'm going through tutorials in C# over at http://www.tutorialspoint.com/csharp/csharp_classes.htm

I'm a bit confused about the Classes tutorial which i linked, Specifically this line:

Box Box1 = new Box(); // Declare Box1 of type Box

Could someone tell me what exactly every word and symbol does in this line? exept for the comment
Does it declare a new...something? that has all the variables inside class Box?

The order the code is written in confuses me i think.
(The the whole code is in the link)

Thank you  :)

Redliquid~

Link to comment
https://linustechtips.com/topic/308947-c-class-question/
Share on other sites

Link to post
Share on other sites

This line will instantiate, or create a new instance of the Box class. The Box class is like a template, with it, you can create unique Box objects that have different values for the same parameters (length, width etc.)

 

The first word "Box" is the name of the class. 

 

The second word, "Box1" is simply the name of the particular Box object that is being created. It is the name that references the Box object that is created, or instantiated with the word "new."

 

"new" in object oriented programming languages is used when you're actually creating a new instance of a class; in this case, a new Box object.

 

"Box()" is the other component for object creation. The brackets () are used for when there are arguments, or parameters for when an object is created. For example, if the Box class had variables such as length and width in the constructor, you would have to pass values into the parameters when creating a new Box object.

 

e.g. Box b1 = new Box(3, 4);

 

This may seem confusing at first. If it is, I recommend reading up more about object oriented concepts in general to get a better grasp as to what you are doing.

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to comment
https://linustechtips.com/topic/308947-c-class-question/#findComment-4199196
Share on other sites

Link to post
Share on other sites

Box Box1 = new Box();

 

 

So the first Box is the type of object that you want to create.

the "Box1" is the name of that object.

then after the "=" creates a new instance of the "Box" class 

then the "=" brings it all together a puts the new instance ob Box that you created on the right of the "=" and puts in a box object called "Box1".

 

hope this helps.

Link to comment
https://linustechtips.com/topic/308947-c-class-question/#findComment-4199204
Share on other sites

Link to post
Share on other sites

This line will instantiate, or create a new instance of the Box class. The Box class is like a template, with it, you can create unique Box objects that have different values for the same parameters (length, width etc.)

 

The first word "Box" is the name of the class. 

 

The second word, "Box1" is simply the name of the particular Box object that is being created. It is the name that references the Box object that is created, or instantiated with the word "new."

 

"new" in object oriented programming languages is used when you're actually creating a new instance of a class; in this case, a new Box object.

 

"Box()" is the other component for object creation. The brackets () are used for when there are arguments, or parameters for when an object is created. For example, if the Box class had variables such as length and width in the constructor, you would have to pass values into the parameters when creating a new Box object.

 

e.g. Box b1 = new Box(3, 4);

 

This may seem confusing at first. If it is, I recommend reading up more about object oriented concepts in general to get a better grasp as to what you are doing.

beat me to the punch :( hahahha

|CPU: Intel i7-5960X @ 4.4ghz|MoBo: Asus Rampage V|RAM: 64GB Corsair Dominator Platinum|GPU:2-way SLI Gigabyte G1 Gaming GTX 980's|SSD:512GB Samsung 850 pro|HDD: 2TB WD Black|PSU: Corsair AX1200i|COOLING: NZXT Kraken x61|SOUNDCARD: Creative SBX ZxR|  ^_^  Planned Bedroom Build: Red Phantom [quadro is stuck in customs, still trying to find a cheaper way to buy a highend xeon]

Link to comment
https://linustechtips.com/topic/308947-c-class-question/#findComment-4199210
Share on other sites

Link to post
Share on other sites

Here is a book on Java (another object oriented language) that I'm reading. In the first chapter there is a good run down for thinking of problems by breaking down components into objects/abstraction that I recommend reading.

 

While I don't have much experience with C#, I'm pretty sure the principals of OO design are generally the same as in Java.

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to comment
https://linustechtips.com/topic/308947-c-class-question/#findComment-4199212
Share on other sites

Link to post
Share on other sites

Here is a book on Java (another object oriented language) that I'm reading. In the first chapter there is a good run down for thinking of problems by breaking down components into objects/abstraction that I recommend reading.

 

While I don't have much experience with C#, I'm pretty sure the principals of OO design are generally the same as in Java.

Thank you so much :)  i really appreciate the thorough explanation and the link to the book ^^

And thanks to everyone else to  :)

Redliquid~

Link to comment
https://linustechtips.com/topic/308947-c-class-question/#findComment-4199251
Share on other sites

Link to post
Share on other sites

Thank you so much :)  i really appreciate the thorough explanation and the link to the book ^^

And thanks to everyone else to  :)

 

No problem, feel free to ask more questions. I'm still very much in the beginning of learning all of this as well. 

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to comment
https://linustechtips.com/topic/308947-c-class-question/#findComment-4199256
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×