How to use extension method for assignment in c#

Testme
Testme
Member
2 Points
1 Posts

Can we use assignment method in c# for assignment purpose? I'm trying to use like this:

class SomeClass
{
   int i = 10; // the value was i was 9;
   i = i.Add(2); // here 10 + 2
   Console.WriteLine(i); // it is printing 12
}

Extension method as:

   public static int Add(this int firstInteger, int secondInteger)
   {
      return (firstInteger + secondInteger);
   }

But it not working as expected.

Views: 245
Total Answered: 0
Total Marked As Answer: 0
Posted On: 25-Oct-2023 06:21

Share:   fb twitter linkedin
Answers
 Log In to Chat