Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Second file: Class1.cs

C#
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; } }




}


First file: Program.cs
C#
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();


        }
    }


I am trying to understand the partial class concepts i have written simple program to add and subtract it all works but i always get the output has 20 and -20 ..I don't know why do i get the same output i have tried changing the numbers still the same
Posted
Comments
ZurdoDev 27-May-14 10:06am    
Just debug it. Step through the code and watch what happens.

1 solution

It's just a typo. In the A property you assign to _b instead of _a.

 
Share this answer
 
Comments
ShaHam11 27-May-14 10:22am    
Thank you
CHill60 27-May-14 10:43am    
Good spot! 5'd
Shmuel Zang 27-May-14 11:05am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900