Click here to Skip to main content
15,891,697 members
Home / Discussions / C#
   

C#

 
GeneralRe: What is the best way to call methods in a commom class? Pin
Not Active21-Oct-09 7:49
mentorNot Active21-Oct-09 7:49 
GeneralRe: What is the best way to call methods in a commom class? Pin
dan!sh 21-Oct-09 7:59
professional dan!sh 21-Oct-09 7:59 
GeneralRe: What is the best way to call methods in a commom class? Pin
Not Active21-Oct-09 8:28
mentorNot Active21-Oct-09 8:28 
Questionscript Pin
netJP12L21-Oct-09 4:53
netJP12L21-Oct-09 4:53 
AnswerRe: script Pin
dan!sh 21-Oct-09 5:29
professional dan!sh 21-Oct-09 5:29 
AnswerRe: script Pin
Rob Branaghan21-Oct-09 5:32
Rob Branaghan21-Oct-09 5:32 
QuestionSerialization of a class which is inherriting from the TreeNode class Pin
mhouck21-Oct-09 3:49
mhouck21-Oct-09 3:49 
QuestionHow to Add a Column to an imported excel file to a DataGridView . Pin
nassimnastaran21-Oct-09 3:39
nassimnastaran21-Oct-09 3:39 
AnswerRe: How to Add a Column to an imported excel file to a DataGridView . Pin
dan!sh 21-Oct-09 5:28
professional dan!sh 21-Oct-09 5:28 
GeneralRe: How to Add a Column to an imported excel file to a DataGridView . Pin
nassimnastaran21-Oct-09 6:20
nassimnastaran21-Oct-09 6:20 
GeneralRe: How to Add a Column to an imported excel file to a DataGridView . Pin
dan!sh 21-Oct-09 7:57
professional dan!sh 21-Oct-09 7:57 
GeneralRe: How to Add a Column to an imported excel file to a DataGridView . Pin
nassimnastaran21-Oct-09 19:03
nassimnastaran21-Oct-09 19:03 
QuestionMDIParent Pin
Socheat.Net21-Oct-09 3:33
Socheat.Net21-Oct-09 3:33 
AnswerRe: MDIParent Pin
dan!sh 21-Oct-09 5:26
professional dan!sh 21-Oct-09 5:26 
Question[Message Deleted] Pin
RINSON VARGHESE21-Oct-09 2:40
RINSON VARGHESE21-Oct-09 2:40 
AnswerRe: c# RePost Pin
Richard MacCutchan21-Oct-09 2:42
mveRichard MacCutchan21-Oct-09 2:42 
Question[Message Deleted] Pin
RINSON VARGHESE21-Oct-09 2:39
RINSON VARGHESE21-Oct-09 2:39 
AnswerRe: advantages of c# Pin
Richard MacCutchan21-Oct-09 2:41
mveRichard MacCutchan21-Oct-09 2:41 
GeneralRe: advantages of c# Pin
musefan21-Oct-09 2:47
musefan21-Oct-09 2:47 
QuestionREF AND OUT VARIABLES Pin
RINSON VARGHESE21-Oct-09 2:10
RINSON VARGHESE21-Oct-09 2:10 
AnswerRe: REF AND OUT VARIABLES Pin
Luc Pattyn21-Oct-09 2:17
sitebuilderLuc Pattyn21-Oct-09 2:17 
AnswerRe: REF AND OUT VARIABLES [modified] Pin
musefan21-Oct-09 2:43
musefan21-Oct-09 2:43 
Well an OUT wont compile if you don't set it in the function, a REF does not need settings. Thou, why would you use a REF if you didn't plan on using it anyway. Maybe one path uses it, other path does not.

Maybe a better example would be if you were to re-use the value in other functions, for example consider the following sample...

ref int SomeData;

public void Setup(ref int data)
{
    SomeData = data;
}

public void Add5()
{
   SomeData += 5;
}


...pointless? Yes. Doe's it compile? I don't know. But would not work with the OUT parameter.


[EDIT] It does not compile

Next attempt...

If you where to design a class library that was to be used for somebody else then it could be useful.

You could use REF to ensure that the value was set before passing in, and you could use out if you didn't care what the value was to start with. Examples...

public void (out int i)
{
    i = 10;
}

public void (ref int i)
{
    i = i + 5;//would break if not already set
}


...Maybe this is what Luc was getting at


[EDIT] Just me again...

I worked out a better usage. Consider the following struct instead of a basic datatype.

struct Sample{
   public string A;
   public string B;

   public Sample(string a, string b)
   {
      A = a;
      B = b;
   }   
}


If you use this struct with REF, then you can change B and keep A the same, if you use OUT then you are required to initialize the data and thus lose all data.

This is the same for passing Controls (for whatever reason you would want to)

Life goes very fast. Tomorrow, today is already yesterday.

modified on Wednesday, October 21, 2009 9:12 AM

GeneralRe: REF AND OUT VARIABLES Pin
Luc Pattyn21-Oct-09 4:16
sitebuilderLuc Pattyn21-Oct-09 4:16 
AnswerRe: REF AND OUT VARIABLES Pin
Ghydo21-Oct-09 2:47
Ghydo21-Oct-09 2:47 
GeneralRe: REF AND OUT VARIABLES Pin
Ghydo21-Oct-09 2:53
Ghydo21-Oct-09 2:53 

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.