Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
AnswerRe: Semi modal dialog? Pin
Amit Kumar Chikara11-Sep-06 1:01
Amit Kumar Chikara11-Sep-06 1:01 
AnswerRe: Semi modal dialog? Pin
Coding C#11-Sep-06 4:47
Coding C#11-Sep-06 4:47 
QuestionLoading and Image, Slows my Form...??? Pin
baajhan10-Sep-06 23:50
baajhan10-Sep-06 23:50 
AnswerRe: Loading and Image, Slows my Form...??? Pin
Andrei Ungureanu11-Sep-06 0:01
Andrei Ungureanu11-Sep-06 0:01 
QuestionAccessing a method in another file Pin
Yustme10-Sep-06 23:50
Yustme10-Sep-06 23:50 
AnswerRe: Accessing a method in another file Pin
Andrei Ungureanu10-Sep-06 23:55
Andrei Ungureanu10-Sep-06 23:55 
GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 0:23
Yustme11-Sep-06 0:23 
AnswerRe: Accessing a method in another file Pin
Christian Graus11-Sep-06 0:10
protectorChristian Graus11-Sep-06 0:10 
If a method is static, then you can call it from anywhere in your project. If it's not static, you need an instance of the class to call the methods on.

Class C1
{
private int n = 0;
private static int s = 0;

public int Int { get { return n; } }
public int IntS { get { return s; } }

public void Add(int i) { n += i; }

public static AddS(int i) { s+=i; }
}

Class C2
{
public DoStuff()
{
C1.AddS(10);
Console.WriteLine(C1.IntS.ToString()); // 10
C1 c1 = new C1();
c1.Add(5);
Console.WriteLine(c1.Int.ToString()); // 5

C1 c2 = new C1();
c2.Add(52);
// c2.Int now = 52, c1.Int still = 5, C1.IntS still = 10
C1.AddS(10);
Console.WriteLine(C1.IntS.ToString()); // 20
c1.Add(12);
Console.WriteLine(c1.Int.ToString()); // 17
Console.WriteLine(c2.Int.ToString()); // 52
}
}

The most common mistake I've seen is for people to have one instance of a class, to be in another class where they don't currently have access to that instance, so they create a new instance ( often of a form ) and try to change variables on that. this won't ever change variables on any instance bar the new one, unless they are static.

Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 0:29
Yustme11-Sep-06 0:29 
GeneralRe: Accessing a method in another file Pin
Christian Graus11-Sep-06 0:54
protectorChristian Graus11-Sep-06 0:54 
GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 1:04
Yustme11-Sep-06 1:04 
GeneralRe: Accessing a method in another file Pin
Christian Graus11-Sep-06 1:12
protectorChristian Graus11-Sep-06 1:12 
GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 1:18
Yustme11-Sep-06 1:18 
GeneralRe: Accessing a method in another file Pin
mesmer11-Sep-06 1:42
mesmer11-Sep-06 1:42 
GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 1:53
Yustme11-Sep-06 1:53 
GeneralRe: Accessing a method in another file Pin
Christian Graus11-Sep-06 1:44
protectorChristian Graus11-Sep-06 1:44 
GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 1:51
Yustme11-Sep-06 1:51 
GeneralRe: Accessing a method in another file Pin
Christian Graus11-Sep-06 2:13
protectorChristian Graus11-Sep-06 2:13 
GeneralRe: Accessing a method in another file Pin
Yustme11-Sep-06 2:44
Yustme11-Sep-06 2:44 
Questionasynchronous sockets vs remoting Pin
saqib8210-Sep-06 23:47
saqib8210-Sep-06 23:47 
AnswerRe: asynchronous sockets vs remoting Pin
Andrei Ungureanu10-Sep-06 23:54
Andrei Ungureanu10-Sep-06 23:54 
AnswerRe: asynchronous sockets vs remoting Pin
Rob Philpott11-Sep-06 3:22
Rob Philpott11-Sep-06 3:22 
QuestionHow to retrieve data from DataGridView Pin
Rip Kirby10-Sep-06 23:08
Rip Kirby10-Sep-06 23:08 
QuestionVideo to Flash (.flv) Pin
AB777110-Sep-06 22:18
AB777110-Sep-06 22:18 
AnswerRe: Video to Flash (.flv) Pin
g00fyman10-Sep-06 22:52
g00fyman10-Sep-06 22:52 

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.