using System; using System.Collections.Generic; using System.Linq; using System.Text; public partial class TestClass { public TestClass(int x, int y) { _a = x; _b = y; } public int A { get { return _a; } set { _b = value; } } public int B { get { return _b; } set { _b = value; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; partial class TestClass { private int _a, _b; public TestClass() { Console.WriteLine("Test Class Default Constructor"); } public void Add() { Console.WriteLine("Addition Method"); Console.WriteLine(_a+_b); } public void Sub() { Console.WriteLine("Subtraction Method"); Console.WriteLine(_a - _b); } } class Program { static void Main(string[] args) { TestClass t = new TestClass(); t.A=10; t.B = 20; t.Add(); t.Sub(); } }
It's just a typo. In the A property you assign to _b instead of _a.
A
_b
_a
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)