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

C#

 
GeneralRe: please help me out in creating image from stream Pin
Christian Graus7-Feb-05 10:03
protectorChristian Graus7-Feb-05 10:03 
Generalfirebird database Vs MSDE engine Pin
ppp0016-Feb-05 22:08
ppp0016-Feb-05 22:08 
GeneralRe: firebird database Vs MSDE engine Pin
Judah Gabriel Himango7-Feb-05 4:18
sponsorJudah Gabriel Himango7-Feb-05 4:18 
Generalretrieve QueryString Value Pin
Adnan Siddiqi6-Feb-05 21:58
Adnan Siddiqi6-Feb-05 21:58 
GeneralRe: retrieve QueryString Value Pin
Heath Stewart7-Feb-05 9:57
protectorHeath Stewart7-Feb-05 9:57 
GeneralBitArray to integer Pin
Md Saleem Navalur6-Feb-05 21:34
Md Saleem Navalur6-Feb-05 21:34 
GeneralRe: BitArray to integer Pin
leppie6-Feb-05 22:37
leppie6-Feb-05 22:37 
GeneralC# function calling mechanism Pin
Siddhartha Ghosh6-Feb-05 21:23
Siddhartha Ghosh6-Feb-05 21:23 
Consider the following C# code -

class TestClass
{
public string str;
}

class TestApplication
{

static void Upper1 ( string strParam )
{
strParam = strParam.ToUpper ();
}

static void Upper2( TestClass tc )
{
tc.str = (tc.str) .ToUpper ();
}

static void Main ( string[] args )
{

string s = "lower 1";
Upper1 ( s );
Console.WriteLine ( s );

TestClass tc = new TestClass();
tc.str = "lower 2";
Upper2 ( tc );
Console.WriteLine ( tc.str );

}
}

The output of this code on execution is as follows -


lower 1
LOWER 2
Press any key to continue


I am new to C# and totally confused over the outcome. As far as I know both "string" and "class type" are reference types in C#. When I am calling "Upper1" with a string as parameter it is behaving as if the parameter was passed "by value" and the changes are not visible in the calling function.

But if I wrap the string within a class and pass an instance of the class as argument to "Upper2", it is behaving as expected.

Can anyone help me in solving this mystery?

Thanks a lot in advance.

Siddhartha

GeneralRe: C# function calling mechanism Pin
Arjan Einbu7-Feb-05 0:28
Arjan Einbu7-Feb-05 0:28 
GeneralRe: C# function calling mechanism Pin
Siddhartha Ghosh7-Feb-05 0:48
Siddhartha Ghosh7-Feb-05 0:48 
GeneralRe: C# function calling mechanism Pin
J4amieC7-Feb-05 1:08
J4amieC7-Feb-05 1:08 
GeneralRe: C# function calling mechanism Pin
Siddhartha Ghosh7-Feb-05 17:34
Siddhartha Ghosh7-Feb-05 17:34 
GeneralRe: C# function calling mechanism Pin
S. Senthil Kumar7-Feb-05 18:38
S. Senthil Kumar7-Feb-05 18:38 
GeneralRe: C# function calling mechanism Pin
Siddhartha Ghosh8-Feb-05 3:06
Siddhartha Ghosh8-Feb-05 3:06 
GeneralRe: C# function calling mechanism Pin
S. Senthil Kumar8-Feb-05 8:54
S. Senthil Kumar8-Feb-05 8:54 
GeneralRe: C# function calling mechanism Pin
Siddhartha Ghosh8-Feb-05 17:49
Siddhartha Ghosh8-Feb-05 17:49 
GeneralRe: C# function calling mechanism Pin
S. Senthil Kumar8-Feb-05 18:09
S. Senthil Kumar8-Feb-05 18:09 
GeneralRe: C# function calling mechanism Pin
Siddhartha Ghosh10-Feb-05 19:18
Siddhartha Ghosh10-Feb-05 19:18 
GeneralVertical Progress Bar Pin
mitreviper6-Feb-05 20:56
mitreviper6-Feb-05 20:56 
GeneralRe: Vertical Progress Bar Pin
Stefan Troschuetz6-Feb-05 23:22
Stefan Troschuetz6-Feb-05 23:22 
GeneralMDI in C#.net Pin
Anonymous6-Feb-05 20:29
Anonymous6-Feb-05 20:29 
GeneralRe: MDI in C#.net Pin
SimonS7-Feb-05 0:07
SimonS7-Feb-05 0:07 
Questionhow to deactivate the keyboard? Pin
ektoras6-Feb-05 19:35
ektoras6-Feb-05 19:35 
AnswerRe: how to deactivate the keyboard? Pin
Heath Stewart7-Feb-05 9:48
protectorHeath Stewart7-Feb-05 9:48 
GeneralNumericUpDown: ValueChanged event not fired Pin
Lizzy6-Feb-05 19:33
Lizzy6-Feb-05 19:33 

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.