using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication4
{
class Program
{
public class TestClass
{
public String name { get; set; }
public int Age { get; set; }
public override bool Equals(object obj)
{
TestClass a = obj as TestClass;
if (a == null) return false;
if (name.Equals(a.name) && Age.Equals(a.Age))
return true;
else
return false;
}
}
static void Main(string[] args)
{
TestClass a = new TestClass()
{
name = "zh",
Age = 14,
};
TestClass b = new TestClass()
{
name="zh",
Age=14,
};
//print ok ,if not override Equals then print no ok!!!
if (Object.Equals(a, b))
{
Console.WriteLine("ok");
}
else
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication4
{
class Program
{
public class TestClass
{
public String name { get; set; }
public int Age { get; set; }
public override bool Equals(object obj)
{
TestClass a = obj as TestClass;
if (a == null) return false;
if (name.Equals(a.name) && Age.Equals(a.Age))
return true;
else
return false;
}
}
static void Main(string[] args)
{
TestClass a = new TestClass()
{
name = "zh",
Age = 14,
};
TestClass b = new TestClass()
{
name="zh",
Age=14,
};
//print ok ,if not override Equals then print no ok!!!
if (Object.Equals(a, b))
{
Console.WriteLine("ok");
}
else
Console.WriteLine("no ok");
//print not ok
if (a== b)
{
Console.WriteLine("ok");
}
else
Console.WriteLine("no ok");
}