Click here to Skip to main content
16,010,268 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem getting a value from a gridview cell Pin
Furi Goled10-Jun-07 17:47
Furi Goled10-Jun-07 17:47 
Questionperformance problem Pin
mdzieg25-May-07 5:08
mdzieg25-May-07 5:08 
AnswerRe: performance problem Pin
Manoj Kumar Rai25-May-07 5:23
professionalManoj Kumar Rai25-May-07 5:23 
GeneralRe: performance problem Pin
mdzieg25-May-07 5:35
mdzieg25-May-07 5:35 
QuestionC# Download Manager (Browser Integration) Pin
Barguast225-May-07 5:05
Barguast225-May-07 5:05 
AnswerRe: C# Download Manager (Browser Integration) Pin
Judah Gabriel Himango25-May-07 6:30
sponsorJudah Gabriel Himango25-May-07 6:30 
QuestionBeginner: references and calls between objects Pin
Christian Bailey25-May-07 5:00
Christian Bailey25-May-07 5:00 
AnswerRe: Beginner: references and calls between objects Pin
Judah Gabriel Himango25-May-07 6:27
sponsorJudah Gabriel Himango25-May-07 6:27 
You're doing good, it's apparent you're picking up some things pretty well.

I see your problem. You're thinking, "how can I write a function that just works on some particular object instance (e.g. Counter2)"?

The problem is, that's not the way functions work supposed to work. Functions in C# are either instance functions (they work on the current instance) or static (they work on any instance you pass them). For example, say you want a SayHello() method on your Counter object. You can code it up to work on all Foo objects:

class Counter
{
   public string MyName;

   // This is an instance method, it works on the current instance of this class.
   public void SayHello() 
   { 
      Console.WriteLine(MyName);
   }
}


Now you can go like this:
Counter counter1 = new Counter();
counter1.MyName = "I am the first counter!";

Counter counter2 = new Counter();
counter2.MyName = "I am the second counter!";

counter1.SayHello(); // prints "I am the first counter"
counter2.SayHello(); // prints "I am the second counter"


See what happened? The SayHello method worked on the current instance.

Static methods don't belong to any instance; therefore they have to be passed the instance to work on:

class Counter
{
   public static void StaticSayHelloMethod(Counter instanceToUse)
   {
      Console.WriteLine(instanceToUse.MyName);
   }
}


Now if you want to use that, you have to pass the instance in:

StaticSayHelloMethod(counter1); // prints "I am the first counter!"
StaticSayHelloMethod(counter2); // prints "I am the second counter!"


Does that answer your question?

p.s. next time use <pre> tags around your code (e.g. <pre> code goes here </pre> ) when you post it on the forums. This way, formatting will be preserved, your code will be easier to read on the forums, and the likelihood of someone answering your question increases. Smile | :)



Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Trekkie love
The apostle Paul, modernly speaking: Epistles of Paul

Judah Himango


GeneralRe: Beginner: references and calls between objects Pin
Christian Bailey25-May-07 7:28
Christian Bailey25-May-07 7:28 
QuestionHelp with the run an executable program of a number of times Pin
Anka_Ame25-May-07 4:41
Anka_Ame25-May-07 4:41 
AnswerRe: Help with the run an executable program of a number of times Pin
Judah Gabriel Himango25-May-07 4:49
sponsorJudah Gabriel Himango25-May-07 4:49 
AnswerRe: Help with the run an executable program of a number of times Pin
kubben25-May-07 4:49
kubben25-May-07 4:49 
AnswerRe: Help with the run an executable program of a number of times Pin
Luc Pattyn25-May-07 6:04
sitebuilderLuc Pattyn25-May-07 6:04 
GeneralRe: Help with the run an executable program of a number of times Pin
Anka_Ame25-May-07 4:58
Anka_Ame25-May-07 4:58 
GeneralRe: Help with the run an executable program of a number of times Pin
Manoj Kumar Rai25-May-07 5:15
professionalManoj Kumar Rai25-May-07 5:15 
AnswerRe: Help with the run an executable program of a number of times Pin
Wes Aday25-May-07 9:33
professionalWes Aday25-May-07 9:33 
QuestionFlowLayoutPanel and ScrollPositions Pin
zaboboa25-May-07 4:32
zaboboa25-May-07 4:32 
AnswerRe: FlowLayoutPanel and ScrollPositions Pin
Judah Gabriel Himango25-May-07 4:49
sponsorJudah Gabriel Himango25-May-07 4:49 
GeneralRe: FlowLayoutPanel and ScrollPositions Pin
zaboboa25-May-07 5:22
zaboboa25-May-07 5:22 
Questionhow to ingnore some characters in serach by Regular Expressions Pin
hdv21225-May-07 3:46
hdv21225-May-07 3:46 
AnswerRe: how to ingnore some characters in serach by Regular Expressions Pin
Judah Gabriel Himango25-May-07 4:44
sponsorJudah Gabriel Himango25-May-07 4:44 
Questionproblem in inserting data Pin
Mujz.........25-May-07 3:46
Mujz.........25-May-07 3:46 
AnswerRe: problem in inserting data Pin
Judah Gabriel Himango25-May-07 4:14
sponsorJudah Gabriel Himango25-May-07 4:14 
GeneralRe: problem in inserting data Pin
Mujz.........26-May-07 8:48
Mujz.........26-May-07 8:48 
AnswerRe: problem in inserting data Pin
Dave Herren25-May-07 4:20
Dave Herren25-May-07 4: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.