View Single Post
  #5 (permalink)  
Old July 18th, 2007, 08:51 PM
navdeep navdeep is offline
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by David_0223
 You must have a main class that launches your application such as Program.cs. If you add a private static variable and a public statuc 'get' property to that class it will be available throughout your application.

I.E. :

static class Program {
  ...
  static private string m_UserCode = "";
  ...
  static public string UserCode {
    get {
      return m_UserCode;
    }
  }
} // end of class Program

You can set the variable from within class Program but have a read only global value available.

If you need to set the UserCode from another class you could do it if you made the variable protected.



What you don't know can hurt you!
Thanks David. I have tried similiar thing. I created a another class in my Business Object layer called clsUserDetails(static) with two static public properties ie. user_code and user_type which I need throughout the application.

Now I have two classes clsUser ( with all required properties ) and clsUserDetails ( with two static properties ). I need to instantiate clsUser so it is not a static class. Now my question is

1) Is it a good OOPS practice to have a repeat user_code and user_type in both classes. This is my main concern.

2) Anybody can accidentally change user_code and user_type throughout the life of application. It needs to be set only once. Should that be readonly properties and set in clsUserDetails constructor.

Thanks.



Reply With Quote