- Feb 2, 2009
- 1,666
- 0
- 0
using System;
public class ClassData
{
public static string sr(string str)
{
string newString = "Dee " + str;
return newString;
}
public static void sr2(ref string str)
{
str = "Dee";
}
public ClassData()
{
}
}
public class App
{
public static void Main(string[] args)
{
string str = ClassData.sr("Hello");
Console.WriteLine(str); // Produces "DeeHello" as output
string hello = "Hello";
ClassData.sr2(ref hello);
Console.WriteLine(hello); // Produces "Dee" as output
System.Threading.Thread.Sleep(2000);
}
}
What does it do in this situation? I can't wrap my head around this stuff sometimes 🙁
From the Microsoft site it says "Ref and out parameter passing modes are used to allow a method to alter variables passed in by the caller."
public class ClassData
{
public static string sr(string str)
{
string newString = "Dee " + str;
return newString;
}
public static void sr2(ref string str)
{
str = "Dee";
}
public ClassData()
{
}
}
public class App
{
public static void Main(string[] args)
{
string str = ClassData.sr("Hello");
Console.WriteLine(str); // Produces "DeeHello" as output
string hello = "Hello";
ClassData.sr2(ref hello);
Console.WriteLine(hello); // Produces "Dee" as output
System.Threading.Thread.Sleep(2000);
}
}
What does it do in this situation? I can't wrap my head around this stuff sometimes 🙁
From the Microsoft site it says "Ref and out parameter passing modes are used to allow a method to alter variables passed in by the caller."
