I'm a new comer to the C# and oop world.
I have a little problem about the class properties please kindly help me.
I have a class named "User" in namespace_A . (User is not a static class)
Now I'm going to write a class to the namespace_B and I need to assign some value to a User object. so I do the following
Expand|Select|Wrap|Line Numbers
- using namespace_A;
- namespace namespace_B
- {
- public class MyNewClass
- {
- //class field
- private User _user;
- //property
- public User UserProperty
- {
- get{ return _user; }
- set{ _user = value;}
- }
- //A function
- public void MyFunction()
- {
- //Here I need to set a value to the User class UserID Property
- //I could do it using
- UserProperty.UserID = 1;
- // *** but why the compiler didn't tell me to create an object first before
- // accessing the properties of the User class.
- }
- }
- }