G
Guest
I'm coming from a 3 year C background with some basic knowlegde on the Win32
API. I just started learning C# a day ago and I have a couple questions that
I need cleared up that just have me very confused.
[quesitons]
1.) Whenever you declare a class - MyClass - is the class alive in memory
for the whole duration of the program? If so, then, since it was not created
via the "new" keyword (like an instance is), is it on the heap or stack?
2.) If you create instances of MyClass, you're really just creating copies
of MyClass, like you would create instances of a struct (non-pointer structs)
in C/C++, correct?
3.) When Myclass is not declared inside another class, or namespace for that
matter, why is it that you cannot make MyClass private? Is it because it
would make the class totally useless since you would not be able to create
any instances of it or use it via the MyClass type?
4.) Still pertaining to the above; if in the programs duration, you never
invoke MyClass or create any instances of it, is it still created in memory
or is it *only* created when you create an instance of it or try to access it
via the MyClass type? if it's the latter, would it make any difference if any
member in the class or the class itself was made static?
4.) static keyword; This one has been hitting me like a hammer on the head.
Ok, from what I can derive from my reading so far is that the concept of the
static keyword on members is like using global variables or passing pointers
around to functions in C/C++, Am I correct? Is that its main and/or sole
purpose?
[/questions]
Knowing C, I think C# isn't too difficult. It seemed pretty straight forward
until I came upon classes and static versus non-static members. Anyway, I
hope someone can enlighten me on the above questions; Thanks in advance.
API. I just started learning C# a day ago and I have a couple questions that
I need cleared up that just have me very confused.
[quesitons]
1.) Whenever you declare a class - MyClass - is the class alive in memory
for the whole duration of the program? If so, then, since it was not created
via the "new" keyword (like an instance is), is it on the heap or stack?
2.) If you create instances of MyClass, you're really just creating copies
of MyClass, like you would create instances of a struct (non-pointer structs)
in C/C++, correct?
3.) When Myclass is not declared inside another class, or namespace for that
matter, why is it that you cannot make MyClass private? Is it because it
would make the class totally useless since you would not be able to create
any instances of it or use it via the MyClass type?
4.) Still pertaining to the above; if in the programs duration, you never
invoke MyClass or create any instances of it, is it still created in memory
or is it *only* created when you create an instance of it or try to access it
via the MyClass type? if it's the latter, would it make any difference if any
member in the class or the class itself was made static?
4.) static keyword; This one has been hitting me like a hammer on the head.
Ok, from what I can derive from my reading so far is that the concept of the
static keyword on members is like using global variables or passing pointers
around to functions in C/C++, Am I correct? Is that its main and/or sole
purpose?
[/questions]
Knowing C, I think C# isn't too difficult. It seemed pretty straight forward
until I came upon classes and static versus non-static members. Anyway, I
hope someone can enlighten me on the above questions; Thanks in advance.