2014-11-10 5 views
-2

그래서 저는 대학 수업을 위해 매우 간단한 실험실에서 일하고 있으며 약간의 문제가 있습니다. 내 선생님은 심판을 언제 사용하고 언제 사용하는지 철저히 설명하지 않았습니다. 할당은 ref를 사용하기 위해 사전 작성된 메소드를 변경 한 다음 실행되었는지 확인한 다음 사용하도록 변경합니다. 내가 ref 부분을 가지고있어,하지만 어떻게 사용하는 방법을 다시 작성합니까? 다음은 재산의 참조 및 ref를 초기화 로 할 때 프로그램ref 및 out을 언제 사용합니까?

using System; 

static class Program 
{ 
    /// <summary> 
    /// Purpose: Entry point to your C# program 
    /// </summary> 
    static void Main() 
    { 
     int iVal1 = 5; 
     int iVal2 = 7; 
     //Call the Swap method with two arguments 
     Swap(ref iVal1, ref iVal2); 
     Console.WriteLine("Swapped values first {0:D} second {1:D}", iVal1, iVal2); 
     Console.WriteLine("Press Enter to continue ..."); 
     Console.ReadLine(); 
    }//End Main() 

    /// <summary> 
    /// Purpose: To swap the two parameters passed to this method 
    /// </summary> 
    /// <param name="num1">num1 int, first number</param> 
    /// <param name="num2">num2 int, second number</param> 
    static public void Swap(ref int num1, ref int num2) 
    { 
     int tempInt = num1; 
     num1 = num2; 
     num2 = tempInt; 
    } 
}//End class Program 
+0

[documentation] (http://msdn.microsoft.com/en-us/library/t3c3bfhx.aspx)를 읽었습니까? –

답변

2

out 때 수도 변화 참조.