小编Gar*_*d K的帖子

C#中的扩展方法如何将值分配给父变量,即“ this”变量

我有一个扩展方法的代码,看起来有些像线

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)

我找不到解决方法,请推荐一种解决方案。

c# winforms

2
推荐指数
1
解决办法
127
查看次数

标签 统计

c# ×1

winforms ×1