Friday 6 April 2012

IEQUATABLE INTERFACE



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

namespace ConsoleApplication
{
    class Program : IEquatable
    {
        private int id;
        private string name;
        private double price;
        public Program(int a, string b, int c)
        {
            this.id = a;
            this.name = b;
            this.price = c;
        }
        public bool Equals(Program others)
        {
            return (this.id == others.id) && (this.name == others.name) && (this.price == others.price);
        }
        static void Main(string[] args)
        {
            Program p = new Program(1, "vijay", 2);
            Program p1 = new Program(1, "vijay", 9);
            if (p.Equals(p1))
                Console.WriteLine("the objects are equal");
            else
                Console.WriteLine("not equal");
        }
    }
}

No comments:

Post a Comment