Click here to Skip to main content
15,889,849 members
Home / Discussions / C#
   

C#

 
GeneralRe: sort generic list collection Pin
davidnz30-Mar-11 1:02
davidnz30-Mar-11 1:02 
AnswerRe: sort generic list collection Pin
Luc Pattyn30-Mar-11 1:19
sitebuilderLuc Pattyn30-Mar-11 1:19 
GeneralRe: sort generic list collection Pin
Pete O'Hanlon30-Mar-11 1:55
mvePete O'Hanlon30-Mar-11 1:55 
GeneralRe: sort generic list collection Pin
Luc Pattyn30-Mar-11 2:27
sitebuilderLuc Pattyn30-Mar-11 2:27 
QuestionHow to export Datagrid view data to PDF or Excel in C#? Pin
Manandhar Boy29-Mar-11 23:00
Manandhar Boy29-Mar-11 23:00 
AnswerRe: How to export Datagrid view data to PDF or Excel in C#? Pin
Wayne Gaylard29-Mar-11 23:12
professionalWayne Gaylard29-Mar-11 23:12 
AnswerRe: How to export Datagrid view data to PDF or Excel in C#? Pin
BobJanova30-Mar-11 23:40
BobJanova30-Mar-11 23:40 
QuestionHow to reference the loaded instance of Class A in Class B Pin
Member 779716729-Mar-11 16:45
Member 779716729-Mar-11 16:45 
AnswerRe: How to reference the loaded instance of Class A in Class B Pin
Dave Kreskowiak29-Mar-11 17:10
mveDave Kreskowiak29-Mar-11 17:10 
AnswerRe: How to reference the loaded instance of Class A in Class B Pin
dan!sh 29-Mar-11 17:56
professional dan!sh 29-Mar-11 17:56 
AnswerRe: How to reference the loaded instance of Class A in Class B Pin
GlobX29-Mar-11 18:19
GlobX29-Mar-11 18:19 
GeneralRe: How to reference the loaded instance of Class A in Class B Pin
dan!sh 29-Mar-11 19:33
professional dan!sh 29-Mar-11 19:33 
GeneralRe: How to reference the loaded instance of Class A in Class B Pin
GlobX29-Mar-11 19:35
GlobX29-Mar-11 19:35 
GeneralRe: How to reference the loaded instance of Class A in Class B Pin
dan!sh 29-Mar-11 19:37
professional dan!sh 29-Mar-11 19:37 
AnswerRe: How to reference the loaded instance of Class A in Class B Pin
PIEBALDconsult29-Mar-11 18:43
mvePIEBALDconsult29-Mar-11 18:43 
AnswerRe: How to reference the loaded instance of Class A in Class B Pin
Nitheesh George29-Mar-11 20:41
Nitheesh George29-Mar-11 20:41 
Hi,

You need to use the Singleton pattern to achieve this. Please find the example below

public class A
{
private static A _instance;
private A()
{}

public static A GetInstance()
{
if(_instance == nulll)
_instance = new A();

return _instance;
}

}

public class B
{
public void Somemethod()
{
A a = A.GetInstance();
.
.
.
do somethig
.
.
}
}

Note that we make the constructor of class A private. And class A holds a instance of itself in _instance variable. This is for to make sure that an out side method cannot create an instance of A. Then we will provide a static method in class A like GetInstance where we create a new instance if an instance is already not exist and return the current instance

Hope this helps

Nitheesh George

http://www.simpletools.co.in
GeneralRe: How to reference the loaded instance of Class A in Class B Pin
PIEBALDconsult30-Mar-11 18:45
mvePIEBALDconsult30-Mar-11 18:45 
Questionhow to separate date and time from a string Pin
aeman29-Mar-11 2:55
aeman29-Mar-11 2:55 
AnswerRe: how to separate date and time from a string Pin
Pete O'Hanlon29-Mar-11 3:17
mvePete O'Hanlon29-Mar-11 3:17 
GeneralRe: how to separate date and time from a string Pin
Thomas Krojer29-Mar-11 3:30
Thomas Krojer29-Mar-11 3:30 
GeneralRe: how to separate date and time from a string [modified] Pin
Pete O'Hanlon29-Mar-11 3:34
mvePete O'Hanlon29-Mar-11 3:34 
AnswerRe: how to separate date and time from a string Pin
RobCroll29-Mar-11 14:45
RobCroll29-Mar-11 14:45 
AnswerRe: how to separate date and time from a string Pin
PIEBALDconsult29-Mar-11 15:05
mvePIEBALDconsult29-Mar-11 15:05 
AnswerRe: how to separate date and time from a string Pin
ascap5-Apr-11 20:14
ascap5-Apr-11 20:14 
AnswerRe: how to separate date and time from a string Pin
Ganesh Kumar Kaki13-Apr-11 2:20
Ganesh Kumar Kaki13-Apr-11 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.