Help me understand c#
Page 1 of 1
CraweN




Posts: 719
Location: Upside down in chair
PostPosted: Mon, 3rd May 2010 11:33    Post subject: Help me understand c#
Hello People.

Still trying to learn c#, having a lot of fun. Thou I still have some questions. One of them is this:

When you normally declare a class variable you also use the new keyword to create it on the heap and call its constructor. But what happends when you ignore the declaring of the variable?

so instead of doing this:

Code:
ExampleClass myClass = new ExampleClass();



you just do this instead:

Code:
new ExampleClass();


Does it just create the constructor, run its code and just wait for the garbage collector to remove it again?


Hardware: Ryzen 3700x, B450 MSI Gaming Pro carbon AC, GTX1080, 32 GB 3200 Mhz cas 14, 256 EVO SSD, 1 TB EVO SSD and 4 TB HDD.
Console: xbox, wii and xbox 360
Back to top
LeoNatan
☢ NFOHump Despot ☢



Posts: 73250
Location: Ramat HaSharon, Israel 🇮🇱
PostPosted: Mon, 3rd May 2010 12:36    Post subject:
Yes, that is exactly what happens. But we can take an example of a class that runs a new thread in its constructor, so the garbage collector won't actually collect the object until that thread is done. And so on, that is just one example. Smile
Back to top
Frant
King's Bounty



Posts: 24656
Location: Your Mom
PostPosted: Mon, 3rd May 2010 16:12    Post subject:
I love the garbage collector in C#.NET... You basically don't have to bother with that crap as long as your code is correct.


Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!

"The sky was the color of a TV tuned to a dead station" - Neuromancer
Back to top
CraweN




Posts: 719
Location: Upside down in chair
PostPosted: Wed, 5th May 2010 19:32    Post subject:
Thanks for the help.

I mentioned some other questions, hopefully someone will help me get some answers.

One of them is not necessary C# specific, but more a question on programming in general. While reading my books on programming, I've noticed that that when the programs gets bigger I sometimes get a little lost trying to figure out whats going on. These programs are pre-programmed for the most part, so I haven't dipped my fingers into all of areas of the program.

What I'm asking is, what is your usual way of reading other peoples code? Starting at the Main method and just working through the program from there? This seems good until I hit programs with Inheritance and/or interfaces.


Hardware: Ryzen 3700x, B450 MSI Gaming Pro carbon AC, GTX1080, 32 GB 3200 Mhz cas 14, 256 EVO SSD, 1 TB EVO SSD and 4 TB HDD.
Console: xbox, wii and xbox 360
Back to top
tainted4ever
VIP Member



Posts: 11336

PostPosted: Wed, 5th May 2010 21:13    Post subject:
CraweN wrote:
Thanks for the help.

I mentioned some other questions, hopefully someone will help me get some answers.

One of them is not necessary C# specific, but more a question on programming in general. While reading my books on programming, I've noticed that that when the programs gets bigger I sometimes get a little lost trying to figure out whats going on. These programs are pre-programmed for the most part, so I haven't dipped my fingers into all of areas of the program.

What I'm asking is, what is your usual way of reading other peoples code? Starting at the Main method and just working through the program from there? This seems good until I hit programs with Inheritance and/or interfaces.
There's no methodology for understanding other people's code. You just gotta spend time studying it. Personally, I study each of the smaller classes first, then see how they are used and tied together. But you can also start from the Main method as well. There really is no methodology behind it Very Happy

Quote:
I love the garbage collector in C#.NET... You basically don't have to bother with that crap as long as your code is correct.


Yes but when it bugs out (which is rare, but it does happen), you're fucked trying to track down what is happening!
Back to top
LeoNatan
☢ NFOHump Despot ☢



Posts: 73250
Location: Ramat HaSharon, Israel 🇮🇱
PostPosted: Wed, 5th May 2010 21:21    Post subject:
I start from the Main (or comparable high level function), and F12 my way into methods and classes as I go. It doesn't have to be in the order code appears though, usually I go to what I consider more complex, then do a quick review of what is more basic.
This works for me, but sometimes going back to a code I have read, after reading another section is needed.
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group