C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: clarification of the following code Posted by Psightoplazm on 6 Jul 2009 at 1:18 PM
Q1: If you are just learning about C# then metadata isn't something you really really need to worry about at all - your compiler will 100% take care of managing all of this. However - all metadata refers to in .net is just a cache that the CLR uses to reference classes and their methods, parameters, and attributes. It describes both the classes that are inside your program and all of the classes that your classes reference. Yes, this includes information about their members.

Q2 : I'm not sure what you mean by "interact" but all this handles is mapping out all the files of an assembly, and handles resolution of types and resources for that assembly - I don't believe it has much to do with handling multiple assemblies -
Again, this is something you could live the rest of your life not knowing about.

Q3 : ok, so do some more research on exactly what a Class is and an instance of a class. Also look up what "Scope" is and how it relates to class (instance) variables.
Take the following class for example:
public class MyClass
{
    private string myVariable;

    public void SetInternalVariable(string value)
    {
        myVariable = value;
    }

    public string PrintTwoStrings(string myVariable)
    {
        Console.WriteLine(myVariable);
        Console.WriteLine(this.myVariable);
    }
}

Now let's put this into a quick program...
MyClass myInstance1 = new MyClass();
MyClass myInstance2 = new MyClass();

myInstance1.SetInternalVariable("I'm inside instance 1");
myInstance2.SetInternalVariable("I'm inside instance 2");

myInstance1.PrintTwoStrings("Printing instance 1:");
myInstance2.PrintTwoStrings("Printing instance 2:");


Now - both myInstance1 and myInstance2 return different results when calling the PrintTwoStrings method. Think an instance (or object) as a copy of a class in memory. Then think of each class as having a built in special variable called 'this'. The 'this' variable references the instance - or copy - that is currently executing your code.

In some cases you actually have two variables with the same exact name and are only seperated by having different 'scopes'. For example in the method PrintTwoStrings - you have the string variable that was passed to the method named "myVariable" (this is a local scope) - and the private variable declared in your class also named "myVariable" (this is called an instance variable - it has a global scope in your class). If you need to work with the local variable named "myVariable" you simply just type out the name of the variable and C# assumes you mean the most-local variable of that name. Otherwise if you want to reference the variable that is actually attached to the calling instance of your class, you have to use the 'this' keyword. So:
this.myVariable

Sorry - it's really hard to understand this concept until you understand classes and instances better.

Q4 : You are correct - I used poor terminology when describing that. No, you do not overwrite the red car - you merely tell 'car' to point to a different Car object. In a non-managed language you would actually be overwriting the memory that held the previous object.
Managed memory has a ton of code behind the code you are actually writing. For example, when you create a new object in memory - your framework is actually handling all references to that object and keeping track of everything that is referencing that object at all times. During a periodic GC, if your framework sees that no one is referencing an object anymore - it marks that memory back to unreserved. The next time an object needs to be created - that memory can then be used to store its information.

My suggestion is to really focus on Object Oriented Theory and Design. It seems you have a plenty solid understanding of the concept of "Programming" but are struggling with what "Object Oriented" programming is.

Once you get a good grasp on OOP - things in C# will start to make a lot more sense - Also pick up a book on "Design Patterns" - this will help you understand object oriented programming more than anything.

Think of C# as more of a tool to create Object Oriented Code (instead of a tool to create programs):
If you think of it this way then no matter how much you know about C# - if you don't understand what you are trying to make with it then you'll never get anywhere.


></\/~Psightoplasm`~
Thread Tree
Fraz clarification of the following code on 2 Jul 2009 at 9:49 AM
Psightoplazm Re: clarification of the following code on 2 Jul 2009 at 12:51 PM
Fraz Re: clarification of the following code on 3 Jul 2009 at 3:48 AM
Psightoplazm Re: clarification of the following code on 6 Jul 2009 at 1:18 PM
Fraz Re: clarification of the following code on 9 Jul 2009 at 3:13 AM
DataDink Re: clarification of the following code on 9 Jul 2009 at 1:29 PM
Fraz Re: clarification of the following code on 10 Jul 2009 at 2:13 AM
Fraz one large gap in my knowledge on 11 Jul 2009 at 4:34 AM
DataDink Re: one large gap in my knowledge on 11 Jul 2009 at 8:05 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.