<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FLanguage_Basics%2Fref</id>
		<title>Csharp/CSharp Tutorial/Language Basics/ref - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FLanguage_Basics%2Fref"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/ref&amp;action=history"/>
		<updated>2026-04-30T01:40:02Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/ref&amp;diff=6522&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/ref&amp;diff=6522&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/ref&amp;diff=6523&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/ref&amp;diff=6523&amp;oldid=prev"/>
				<updated>2010-05-26T12:19:18Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Change string using ref keyword==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void UpperCaseThisString(ref string s)&lt;br /&gt;
  {&lt;br /&gt;
    s = s.ToUpper();&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    string s = &amp;quot;str&amp;quot;;&lt;br /&gt;
    Console.WriteLine(&amp;quot;-&amp;gt; Before: {0}&amp;quot;, s);&lt;br /&gt;
    UpperCaseThisString(ref s);&lt;br /&gt;
    Console.WriteLine(&amp;quot;-&amp;gt; After: {0}\n&amp;quot;, s);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;-&amp;gt; Before: str&lt;br /&gt;
-&amp;gt; After: STR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Passing Parameters by Value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;public class Swapper {&lt;br /&gt;
    public void Swap(int x, int y) {&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;In Swap(): initial x = &amp;quot; + x + &amp;quot;, y = &amp;quot; + y);&lt;br /&gt;
        int temp = x;&lt;br /&gt;
        x = y;&lt;br /&gt;
        y = temp;&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;In Swap(): final   x = &amp;quot; + x + &amp;quot;, y = &amp;quot; + y);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        int x = 2;&lt;br /&gt;
        int y = 5;&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;In Main(): initial x = &amp;quot; + x + &amp;quot;, y = &amp;quot; + y);&lt;br /&gt;
        Swapper mySwapper = new Swapper();&lt;br /&gt;
        mySwapper.Swap(x, y);&lt;br /&gt;
        System.Console.WriteLine(&amp;quot;In Main(): final   x = &amp;quot; + x + &amp;quot;, y = &amp;quot; + y);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Swap two references.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System; &lt;br /&gt;
 &lt;br /&gt;
class RefSwap { &lt;br /&gt;
  int a, b; &lt;br /&gt;
   &lt;br /&gt;
  public RefSwap(int i, int j) { &lt;br /&gt;
    a = i; &lt;br /&gt;
    b = j; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public void show() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;a: {0}, b: {1}&amp;quot;, a, b); &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // This method changes its arguments. &lt;br /&gt;
  public void swap(ref RefSwap ob1, ref RefSwap ob2) { &lt;br /&gt;
    RefSwap t; &lt;br /&gt;
  &lt;br /&gt;
    t = ob1; &lt;br /&gt;
    ob1 = ob2; &lt;br /&gt;
    ob2 = t; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    RefSwap x = new RefSwap(1, 2); &lt;br /&gt;
    RefSwap y = new RefSwap(3, 4); &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;x before call: &amp;quot;); &lt;br /&gt;
    x.show(); &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;y before call: &amp;quot;); &lt;br /&gt;
    y.show(); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    // exchange the objects to which x and y refer &lt;br /&gt;
    x.swap(ref x, ref y);  &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;x after call: &amp;quot;); &lt;br /&gt;
    x.show(); &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;y after call: &amp;quot;); &lt;br /&gt;
    y.show(); &lt;br /&gt;
 &lt;br /&gt;
  } &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;x before call: a: 1, b: 2&lt;br /&gt;
y before call: a: 3, b: 4&lt;br /&gt;
x after call: a: 3, b: 4&lt;br /&gt;
y after call: a: 1, b: 2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Swap two values==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System; &lt;br /&gt;
 &lt;br /&gt;
class Swap { &lt;br /&gt;
  // This method now changes its arguments. &lt;br /&gt;
  public void swap(ref int a, ref int b) { &lt;br /&gt;
    int t; &lt;br /&gt;
  &lt;br /&gt;
    t = a; &lt;br /&gt;
    a = b; &lt;br /&gt;
    b = t; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    Swap ob = new Swap(); &lt;br /&gt;
 &lt;br /&gt;
    int x = 10, y = 20; &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;x and y before call: &amp;quot; + x + &amp;quot; &amp;quot; + y); &lt;br /&gt;
 &lt;br /&gt;
    ob.swap(ref x, ref y);  &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;x and y after call: &amp;quot; + x + &amp;quot; &amp;quot; + y); &lt;br /&gt;
  } &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;x and y before call: 10 20&lt;br /&gt;
x and y after call: 20 10&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use out for reference type==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MyClass&lt;br /&gt;
{&lt;br /&gt;
   public int Val = 20;                     &lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void MyMethod(out MyClass f1, out int f2)&lt;br /&gt;
   {&lt;br /&gt;
      f1 = new MyClass();                   &lt;br /&gt;
      f1.Val = 25;                          &lt;br /&gt;
      f2 = 15;                              &lt;br /&gt;
   }&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      MyClass myObject = null;&lt;br /&gt;
      int intValue;&lt;br /&gt;
      MyMethod(out myObject, out intValue);             &lt;br /&gt;
      Console.WriteLine(&amp;quot;After  -- myObject.Val: {0}, intValue: {1}&amp;quot;, myObject.Val, intValue);&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;After  -- myObject.Val: 25, intValue: 15&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use ref for int value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
&lt;br /&gt;
class MyClass&lt;br /&gt;
{&lt;br /&gt;
   public int Val = 20;                  &lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void MyMethod(ref MyClass myObject, ref int intValue)&lt;br /&gt;
   {&lt;br /&gt;
      myObject.Val = myObject.Val + 5;               &lt;br /&gt;
      intValue = intValue + 5;                       &lt;br /&gt;
   }&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      MyClass myObject = new MyClass();&lt;br /&gt;
      int intValue = 10;&lt;br /&gt;
      Console.WriteLine(&amp;quot;Before -- myObject.Val: {0}, intValue: {1}&amp;quot;, myObject.Val, intValue);&lt;br /&gt;
      MyMethod(ref myObject, ref intValue);          &lt;br /&gt;
      Console.WriteLine(&amp;quot;After  -- myObject.Val: {0}, intValue: {1}&amp;quot;, myObject.Val, intValue);&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Before -- myObject.Val: 20, intValue: 10&lt;br /&gt;
After  -- myObject.Val: 25, intValue: 15&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use ref for reference type==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
&lt;br /&gt;
class MyClass&lt;br /&gt;
{&lt;br /&gt;
   public int Val = 20;                  &lt;br /&gt;
}&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
   static void MyMethod(ref MyClass myObject, ref int intValue)&lt;br /&gt;
   {&lt;br /&gt;
      myObject.Val = myObject.Val + 5;               &lt;br /&gt;
      intValue = intValue + 5;                       &lt;br /&gt;
   }&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      MyClass myObject = new MyClass();&lt;br /&gt;
      int intValue = 10;&lt;br /&gt;
      Console.WriteLine(&amp;quot;Before -- myObject.Val: {0}, intValue: {1}&amp;quot;, myObject.Val, intValue);&lt;br /&gt;
      MyMethod(ref myObject, ref intValue);          &lt;br /&gt;
      Console.WriteLine(&amp;quot;After  -- myObject.Val: {0}, intValue: {1}&amp;quot;, myObject.Val, intValue);&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Before -- myObject.Val: 20, intValue: 10&lt;br /&gt;
After  -- myObject.Val: 25, intValue: 15&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use ref to pass a value type by reference==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The ref parameter modifier causes C# to create a call-by-reference, rather than a call-by-value.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System; &lt;br /&gt;
 &lt;br /&gt;
class RefTest { &lt;br /&gt;
  /* This method changes its argument. &lt;br /&gt;
     Notice the use of ref. */ &lt;br /&gt;
  public void sqr(ref int i) { &lt;br /&gt;
    i = i * i; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    RefTest ob = new RefTest(); &lt;br /&gt;
 &lt;br /&gt;
    int a = 10; &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;a before call: &amp;quot; + a); &lt;br /&gt;
 &lt;br /&gt;
    ob.sqr(ref a); // notice the use of ref &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;a after call: &amp;quot; + a); &lt;br /&gt;
  } &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;a before call: 10&lt;br /&gt;
a after call: 100&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>