我有一个扩展方法的代码,看起来有些像线
parent class
{
int i = 9; // the value was i was 9;
i = i.Add(2); // here 9 + 2
Console.WriteLine(i); // it is printing 11
}
extension class
{
public static int Add(this int firstInteger, int secondInteger)
{
return (firstInteger + secondInteger);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的扩展类,但我需要的是
parent class
{
int i = 9; // the value was i was 9;
i.Add(2); // here 9 + 2
Console.WriteLine(i); // it has to print 11
}
Run Code Online (Sandbox Code Playgroud)
我找不到解决方法,请推荐一种解决方案。