从同一个类读取属性

Jim*_*y D 0 c#

在C#中如果我在课堂上有这个:

public int SomeNumber
{
    get { return 6; }
}
Run Code Online (Sandbox Code Playgroud)

如果函数接收到具有相同名称的变量,如何从同一类中的函数读取(获取)该数字?例:

public bool SomeFunction(int SomeNumber)
{
    check if SomeNumber (the one passed to this function) == SomeNumber (the one from the public int)
}
Run Code Online (Sandbox Code Playgroud)

Tej*_*ejs 7

您只需在方法中调用属性get:

 public void MyMethod()
 {
      var someNum = SomeNumber; // basically, var somNum = this.SomeNumber;
 }
Run Code Online (Sandbox Code Playgroud)

编辑:用OP的编辑澄清:

 public void MyMethod(int someNumber) 
 // Change the naming of your parameter so it doesnt clash with the property
 {
       if(someNumber == SomeNumber)
          // Do Stuff
 }
Run Code Online (Sandbox Code Playgroud)