Click here to Skip to main content
15,881,027 members
Home / Discussions / C#
   

C#

 
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 
QuestionSystem.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
Pierre besquent29-Mar-11 1:19
Pierre besquent29-Mar-11 1:19 
AnswerRe: System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
Pete O'Hanlon29-Mar-11 1:24
mvePete O'Hanlon29-Mar-11 1:24 
GeneralRe: System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
Pierre besquent29-Mar-11 1:29
Pierre besquent29-Mar-11 1:29 
GeneralRe: System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
Pete O'Hanlon29-Mar-11 2:16
mvePete O'Hanlon29-Mar-11 2:16 
GeneralRe: System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
DaveyM6929-Mar-11 7:40
professionalDaveyM6929-Mar-11 7:40 
AnswerRe: System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
Rob Philpott29-Mar-11 1:38
Rob Philpott29-Mar-11 1:38 
AnswerRe: System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); functionality Pin
Luc Pattyn29-Mar-11 1:52
sitebuilderLuc Pattyn29-Mar-11 1:52 
AnswerCross post Pin
Not Active29-Mar-11 2:27
mentorNot Active29-Mar-11 2:27 

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.