Click here to Skip to main content
15,918,808 members
Home / Discussions / C#
   

C#

 
AnswerRe: Increasing the size of the form Pin
stancrm28-May-06 21:17
stancrm28-May-06 21:17 
QuestionC#.Net application Pin
betty_boop27-May-06 9:31
betty_boop27-May-06 9:31 
AnswerRe: C#.Net application Pin
NaNg1524127-May-06 9:34
NaNg1524127-May-06 9:34 
GeneralRe: C#.Net application Pin
Colin Angus Mackay27-May-06 9:41
Colin Angus Mackay27-May-06 9:41 
GeneralRe: C#.Net application Pin
betty_boop27-May-06 9:54
betty_boop27-May-06 9:54 
AnswerRe: C#.Net application Pin
Colin Angus Mackay27-May-06 9:47
Colin Angus Mackay27-May-06 9:47 
GeneralRe: C#.Net application Pin
betty_boop27-May-06 10:04
betty_boop27-May-06 10:04 
GeneralRe: C#.Net application Pin
Colin Angus Mackay27-May-06 10:24
Colin Angus Mackay27-May-06 10:24 
Well, looking at your other post, you seem to have a handle on creating structs (which is a little more advanced than I'd expect)

You create a method inside a class or struct. structs are rarely used, but for the most part are very similar to a class. They, structs, are passed "by value" rather than "by reference". Passing by value means that the "value" is copied when it is passed to a method or assigned to a new variable. Passing by reference means that only a reference to the object is passed, not the object itself. This means there is only one copy of the object.

For the rest of this post every time I use class you can also assume it will work with a struct also.

Now, to create a method you need to know some things.

1. What is it going to be called? Typically method names are verbs or verbal phrases. That means they indicate what they are going to do. e.g. CalculateTime

2. What information does the method need to know in order to work? Because a method is part of a class or struct, it will be able to see the information that the class holds. If the class doesn't hold the information that the method needs it will have to be passed in as parameters. So, a method may need parameters.

3. What information is returned? Not all methods return information, sometimes they just modify the class they are part of. But if a method does return some information you need to know what that is. Is it a string? An int? a DateTime?

4. What can see the method? Is is public, private, protected, internal, or internal protected. Don't worry about all these choices at the moment. The two most common are public and private. public means that everything can see the method, private means that only the class (or other instances of the class) can see the method.

So here is an example all put together:
public Time CalculateTime(int seconds)
{
    // Do stuff that calculates the hours, minute and seconds
}

1. It is called CalculateTime
2. It needs to know how many seconds to use is the calculation. And it needs to know that seconds is an int.
3. It returns a Time object (from the struct I saw in your other post)
4. It is public, which means that anything that has an instance of this class can use it.

The next thing you need to know is how to call the method.

As the method returns something you need somewhere to store that (assuming you are interested in the return value - It is perfectly okay to ignore the return value if you want). In this case we need a variable of type Time.

We also need to know what to pass in to the method. In this case we can use a literal value that is hard coded into the application, but you can use a variable of type int (because that is what the method expects) if you want.

Time calculatedTime = CalculateTime(66);


And that is it.

Does this help?


"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)

My: Website | Blog
GeneralRe: C#.Net application Pin
betty_boop27-May-06 10:36
betty_boop27-May-06 10:36 
GeneralRe: C#.Net application Pin
Ravi Bhavnani27-May-06 10:42
professionalRavi Bhavnani27-May-06 10:42 
GeneralRe: C#.Net application Pin
Colin Angus Mackay27-May-06 10:46
Colin Angus Mackay27-May-06 10:46 
GeneralRe: C#.Net application Pin
betty_boop27-May-06 11:21
betty_boop27-May-06 11:21 
GeneralRe: C#.Net application Pin
Colin Angus Mackay27-May-06 13:41
Colin Angus Mackay27-May-06 13:41 
GeneralRe: C#.Net application Pin
betty_boop28-May-06 9:14
betty_boop28-May-06 9:14 
Questionget whether a checkbox is checked or not ASP.net Pin
DeepToot27-May-06 7:36
DeepToot27-May-06 7:36 
AnswerRe: get whether a checkbox is checked or not ASP.net Pin
maryamf27-May-06 11:33
maryamf27-May-06 11:33 
GeneralRe: get whether a checkbox is checked or not ASP.net Pin
DeepToot27-May-06 12:59
DeepToot27-May-06 12:59 
GeneralRe: get whether a checkbox is checked or not ASP.net Pin
leppie27-May-06 18:32
leppie27-May-06 18:32 
GeneralRe: get whether a checkbox is checked or not ASP.net Pin
DeepToot28-May-06 15:41
DeepToot28-May-06 15:41 
Questiontextbox cursor disable Pin
jackalfb27-May-06 6:20
jackalfb27-May-06 6:20 
AnswerRe: textbox cursor disable Pin
Guffa27-May-06 6:49
Guffa27-May-06 6:49 
GeneralRe: textbox cursor disable Pin
jackalfb27-May-06 9:27
jackalfb27-May-06 9:27 
AnswerRe: textbox cursor disable Pin
Guffa27-May-06 22:50
Guffa27-May-06 22:50 
QuestionDBNull and Uniqe ID Pin
NaNg1524127-May-06 5:42
NaNg1524127-May-06 5:42 
Questionusing the scalar execute mode in ado.net 2.0. help!!! Pin
aenon27-May-06 5:41
aenon27-May-06 5:41 

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.