using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestBasicKnow { class Program { public static void Main(string[] args) { int val1 = 12; int val2 = 12; int result = (val1 == val2) ? 1 : 0; String str1 = "zhao"; String str2 = "zhao"; int result2 = (str1.Equals(str2)) ? 1 : 0; System.Console.WriteLine(result2); System.Console.WriteLine(result); //驗證equals和==的區別 Person person1 = new Person(); Person person2 = new Person(); Person person3 = person1; System.Console.WriteLine(person1.Equals(person2)); System.Console.WriteLine(person3.Equals(person1)); System.Console.WriteLine(person3 == person1); System.Console.WriteLine(person3.Equals(person2)); System.Console.WriteLine(person3 == person2); System.Console.WriteLine((person1.ToString()).Equals(person2.ToString())); System.Console.WriteLine(person1 == person2); System.Console.Read(); } } class Person { static void Method() { string name = "zhao"; int age = 12; } } }