Click here to Skip to main content
16,007,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I get a *real* destructor?! Pin
sreejith ss nair8-Oct-04 1:51
sreejith ss nair8-Oct-04 1:51 
GeneralRe: How can I get a *real* destructor?! Pin
nurglitch8-Oct-04 2:15
nurglitch8-Oct-04 2:15 
GeneralRe: How can I get a *real* destructor?! Pin
Colin Angus Mackay8-Oct-04 3:17
Colin Angus Mackay8-Oct-04 3:17 
GeneralRe: How can I get a *real* destructor?! Pin
Matt Gerrans8-Oct-04 9:32
Matt Gerrans8-Oct-04 9:32 
GeneralSafeNativeMethods Pin
Mikke_x8-Oct-04 0:08
Mikke_x8-Oct-04 0:08 
QuestionHow to add an active directory user to One BuiltIn Group- programmatically Pin
Subin KJ7-Oct-04 23:31
Subin KJ7-Oct-04 23:31 
GeneralPassing variables by ref Pin
Peter Beedell7-Oct-04 22:28
Peter Beedell7-Oct-04 22:28 
GeneralRe: Passing variables by ref Pin
Heath Stewart7-Oct-04 22:38
protectorHeath Stewart7-Oct-04 22:38 
This is all be designed, and well-documented if you read the .NET Framework SDK. While a String is a reference type (and, hence, always passed by reference - at least in C#), it is immutable; any changes you make to the string are actually made on a copy. Why do you think that methods like String.Replace return a string?

If you want to modify a string from a method in a child class, either return a string from your method or default an out or ref parameter like so:
using System;
 
class Test
{
  static void Main()
  {
    string value = "Hello, world!";
    Console.WriteLine(value);
 
    value.Replace("Hello", "Guten tag");
    Console.WriteLine(value); // still prints "Hello, world!"
 
    Change(ref value);
    Console.WriteLine(value);
  }
 
  static void Change(ref string value)
  {
    value = "Tschuss!";
  }
}
For value types - numbers, enumerations, and structures - they are always passed by value, so you have declare value type parameters using out or ref if you plan on changing their values.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: Passing variables by ref Pin
Peter Beedell8-Oct-04 1:35
Peter Beedell8-Oct-04 1:35 
GeneralRe: Passing variables by ref Pin
Heath Stewart8-Oct-04 6:11
protectorHeath Stewart8-Oct-04 6:11 
GeneralFull Screen How to Pin
biran7-Oct-04 22:24
biran7-Oct-04 22:24 
GeneralRe: Full Screen How to Pin
Heath Stewart7-Oct-04 22:32
protectorHeath Stewart7-Oct-04 22:32 
GeneralRe: Full Screen How to Pin
biran7-Oct-04 23:54
biran7-Oct-04 23:54 
GeneralRe: Full Screen How to Pin
Heath Stewart8-Oct-04 6:07
protectorHeath Stewart8-Oct-04 6:07 
QuestionDatabase security - Any suggestions? Pin
totig7-Oct-04 22:21
totig7-Oct-04 22:21 
AnswerRe: Database security - Any suggestions? Pin
Heath Stewart7-Oct-04 22:40
protectorHeath Stewart7-Oct-04 22:40 
AnswerRe: Database security - Any suggestions? Pin
Vasudevan Deepak Kumar8-Oct-04 3:55
Vasudevan Deepak Kumar8-Oct-04 3:55 
GeneralRe: Database security - Any suggestions? Pin
totig8-Oct-04 4:10
totig8-Oct-04 4:10 
GeneralRe: Database security - Any suggestions? Pin
Vasudevan Deepak Kumar8-Oct-04 4:52
Vasudevan Deepak Kumar8-Oct-04 4:52 
QuestionHow to get the PrinterSettings of a Printer? Pin
sachinkalse7-Oct-04 22:10
sachinkalse7-Oct-04 22:10 
AnswerRe: How to get the PrinterSettings of a Printer? Pin
Heath Stewart7-Oct-04 22:23
protectorHeath Stewart7-Oct-04 22:23 
GeneralRe: How to get the PrinterSettings of a Printer? Pin
sachinkalse7-Oct-04 22:49
sachinkalse7-Oct-04 22:49 
GeneralRe: How to get the PrinterSettings of a Printer? Pin
Heath Stewart8-Oct-04 5:57
protectorHeath Stewart8-Oct-04 5:57 
GeneralMAPI programming Pin
ting6687-Oct-04 21:22
ting6687-Oct-04 21:22 
Questionhow to preprocess "ctrl + c" in console program Pin
williamchou7-Oct-04 21:06
williamchou7-Oct-04 21:06 

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.