NR said:
I am new in .NET application but have developed many applications in Visual
FoxPro and Visual Basic.
In my first .NET application, I have a USER class which keeps record of
user
privileges. Is it possible to instantiate this object once in a project(To
avoid back and forth communication with data server), which can be used in
all other classes and forms.
Any kind of help would be appreciated.
Yeah, you can do that as long as you pass the public USER object with any
public properties or methods within USER object that can be acted upon
publicly in the USER object, passing USER object in a form's constructor or
in a method's signature as a parameter.
public class USER
{
#region public properties
public long UserID { get; set; }
public string Username { get; set; }
#endregion
#region public methods
public User GetUser(long id)
{
data access to get the data from data-store
UserID = da.UserID;
UserName = da.Username;
return this;
}
#endregion
}
This is about from wherever you instantiate a new USER object.
USER obj = new USER();
USER userobj = obj.GetUser(22);
This is method signature that you have to pass userobj in it.
public void Somemethod(USER userobj)
{
string userid = userobj.UserID.ToString();
}
the call
Somemethod(userobj);
call to form passing userobj
FormA theform = new FormA(userobj);
FormA constructor
public FormA(USER userobj)
{
objuser = userobj;
}
Objuser would be a public declaration in FormA.
public USER objuser;
__________ Information from ESET NOD32 Antivirus, version of virus signature database 4080 (20090515) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com