Click here to Skip to main content
15,912,504 members
Home / Discussions / C#
   

C#

 
GeneralRe: operating system Pin
debnathrubs9-Feb-07 22:55
debnathrubs9-Feb-07 22:55 
GeneralRe: operating system Pin
Christian Graus9-Feb-07 23:17
protectorChristian Graus9-Feb-07 23:17 
GeneralRe: operating system Pin
debnathrubs9-Feb-07 23:24
debnathrubs9-Feb-07 23:24 
GeneralRe: operating system Pin
Colin Angus Mackay10-Feb-07 0:25
Colin Angus Mackay10-Feb-07 0:25 
GeneralRe: operating system Pin
Dave Kreskowiak10-Feb-07 4:04
mveDave Kreskowiak10-Feb-07 4:04 
QuestionDifferent speeds using Pointers Pin
AlexZieg719-Feb-07 21:09
AlexZieg719-Feb-07 21:09 
QuestionMethods and Calling Methods Pin
JMOdom9-Feb-07 20:33
JMOdom9-Feb-07 20:33 
AnswerRe: Methods and Calling Methods Pin
Christian Graus9-Feb-07 21:00
protectorChristian Graus9-Feb-07 21:00 
OK, basically a method is a group of C# statements that do something. They can do *anything* you like, but typically the idea is that a method is like a building block. Once you have the mould, you can make all the blocks you need. Once you define a method, you can call it whenever you like.

namespace test
{
static void Main()
{
Method1();
Method2();
Method1();
}

private void Method1()
{
Console.WriteLine("in method1");
}

private void Method2()
{
Console.Write("not ");
}
}

So, this example is trivial, usually a method would do a calculation, or connect to a datatabase, or some other 'useful' thing. The point is, I have two methods, and I can call each, as often and whenever I like. This means, for example, if my database won't connect, I know the database connect method is where I look for an error, instead of having one big clump of code and trying to work out which bit is running when the problem occurs.

You can also pass values into a method, and you can return values. A canonical example would be

private int Add(int x, int y)
{
return x + y;
}

No-one would write a method like this, but you see that to call this method, you need to give it two numbers to add, like this:

int total = Add(1, 6);

The variable called 'total' now equals 7. You can also pass values from variables, like so:

int v= 27;
int n = 1042;
int e = Add(v, n);

You'll note, the names don't have to be the same, you can use whatever names you like, they don't need to match the names given within the method signature, those names only exist so you can refer to the values within the method.

Does that help ?


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

GeneralRe: Methods and Calling Methods Pin
chris.hagelstein5-Apr-10 8:07
chris.hagelstein5-Apr-10 8:07 
QuestionAccessing dbf database tables instead of database Pin
kalyan_24169-Feb-07 19:36
kalyan_24169-Feb-07 19:36 
QuestionResponse.Redirect Failedon login Pin
dabuskol9-Feb-07 18:14
dabuskol9-Feb-07 18:14 
QuestionException has been thrown by the target of an invocation Pin
Kasic Slobodan9-Feb-07 16:44
Kasic Slobodan9-Feb-07 16:44 
AnswerRe: Exception has been thrown by the target of an invocation Pin
Stefan Troschuetz9-Feb-07 21:35
Stefan Troschuetz9-Feb-07 21:35 
GeneralRe: Exception has been thrown by the target of an invocation Pin
Kasic Slobodan11-Feb-07 5:30
Kasic Slobodan11-Feb-07 5:30 
QuestionHow do I Index into a grid view while typing string? Pin
Edwin Smith9-Feb-07 16:12
Edwin Smith9-Feb-07 16:12 
QuestionGripStyle Pin
max292979-Feb-07 15:32
max292979-Feb-07 15:32 
AnswerRe: GripStyle Pin
PIEBALDconsult9-Feb-07 17:00
mvePIEBALDconsult9-Feb-07 17:00 
QuestionMore Options on a ToolStrip Pin
max292979-Feb-07 15:29
max292979-Feb-07 15:29 
QuestionCan I create a personalized window? Pin
Khoramdin9-Feb-07 15:06
Khoramdin9-Feb-07 15:06 
AnswerRe: Can I create a personalized window? Pin
PIEBALDconsult9-Feb-07 17:02
mvePIEBALDconsult9-Feb-07 17:02 
QuestionRe: Can I create a personalized window? Pin
Khoramdin9-Feb-07 22:00
Khoramdin9-Feb-07 22:00 
QuestioncurrentMotion[0]["MeetingDateProp"].ToString("MMM dd, yyyy") Pin
Glen Harvy9-Feb-07 12:06
Glen Harvy9-Feb-07 12:06 
AnswerRe: currentMotion[0]["MeetingDateProp"].ToString("MMM dd, yyyy") Pin
Christian Graus9-Feb-07 12:12
protectorChristian Graus9-Feb-07 12:12 
GeneralRe: currentMotion[0]["MeetingDateProp"].ToString("MMM dd, yyyy") Pin
Glen Harvy9-Feb-07 14:26
Glen Harvy9-Feb-07 14:26 
AnswerRe: currentMotion[0]["MeetingDateProp"].ToString("MMM dd, yyyy") Pin
Ed.Poore9-Feb-07 12:42
Ed.Poore9-Feb-07 12:42 

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.