Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

I have this class

namespace User
{
public class ApplicationData
{
private static ApplicationData appData = null;
private string nesto;
public static ApplicationData getInstance()
{
if (appData == null)
{
appData = new ApplicationData();
}
return appData;
}

public string Nesto
{
get
{

return nesto;
}
set { nesto = value; }
}

}
}

on all my forms I have to use Nesto but I don't know how to call this class to my forms
Posted
Comments
Jameel VM 10-Sep-13 4:25am    
r u try to implement Singleton design pattern?
Jameel VM 10-Sep-13 4:26am    
What are you trying to implement?
shonezi 10-Sep-13 4:29am    
yes, yes, singleton design pattern, I forgot the name :) I want to use that string on each form which will be filled with data on main form, so with this design pattern I want to have that data on each form, but I dont know how to call it
Jameel VM 10-Sep-13 4:38am    
did you know why singleton pattern?
shonezi 10-Sep-13 4:45am    
friend recommended it to me, because on my main form I have bound that string Nesto with datatable (filled with data from sql server) but the data from Nesto has to be avaliable to every form I have, and now I have problem with actually calling the class with that filled data.

1 solution

A singleton is a class which only allows a single instance of itself to be created, and usually gives simple access to that instance
For Singleton you should also set constructor as private. You can call the getInstance without creating an object.Because the method is static.
For example
C#
ApplicationData obj= ApplicationData.getInstance();


It will create an instance of ApplicationData class on the first time. Then again you try to call this process it will restrict .
Hope this helps
 
Share this answer
 
v2
Comments
shonezi 10-Sep-13 4:56am    
THANK YOU< THANK YOU, THANK YOU!!! it works!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900