OOP in C#

Calculator.cs

namespace ConsoleApp6.Math

{
    public class Calculator
    {
        public int Add(int a,int b)
        {
            return a + b;
        }
    }
}

Program.cs

using ConsoleApp6.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            Person john = new Person();
            john.FirstName = "John";
            john.LastName = "Smith";
            john.Introduce();

            Calculator calculator = new Calculator();
            var result = calculator.Add(1, 2);
            System.Console.WriteLine(result);
        }
    }
}

Person.cs

using System;

namespace ConsoleApp6
{
    public class Person
    {
        public string FirstName;
        public string LastName;

        public void Introduce()
        {
            Console.WriteLine("My name is:"+FirstName+" "+LastName);
        }
    }
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *