本文整理汇总了C#中Circle.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Circle.Equals方法的具体用法?C# Circle.Equals怎么用?C# Circle.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Circle
的用法示例。
在下文中一共展示了Circle.Equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Circle_EqualsObject
public void Circle_EqualsObject()
{
var circle1 = new Circle(123, 456, 100);
var circle2 = new Circle(123, 456, 100);
TheResultingValue(circle1.Equals((Object)circle2)).ShouldBe(true);
TheResultingValue(circle1.Equals("This is a test")).ShouldBe(false);
}
示例2: Circle_EqualsCircle
public void Circle_EqualsCircle()
{
var circle1 = new Circle(123, 456, 100);
var circle2 = new Circle(123, 456, 100);
var circle3 = new Circle(123, 555, 100);
var circle4 = new Circle(222, 456, 100);
TheResultingValue(circle1.Equals(circle2)).ShouldBe(true);
TheResultingValue(circle1.Equals(circle3)).ShouldBe(false);
TheResultingValue(circle1.Equals(circle4)).ShouldBe(false);
}
示例3: ConstructorsEqualityTest
public void ConstructorsEqualityTest()
{
Circle circle1 = new Circle(84, 64, 32);
Circle circle2 = new Circle(52, 32, 64, false);
Assert.True(circle1.Equals(circle2), "the circles should be equal");
Assert.Equal(circle1.GetHashCode(), circle2.GetHashCode()); //the circles should generate the same hash code
}
示例4: Main
static void Main(string[] args)
{
Circle obj1 = new Circle { Radius = 100.1 };
Circle obj2 = new Circle { Radius = 100.9 };
//测试覆盖的方法
Console.WriteLine(obj1.GetHashCode());//100100
Console.WriteLine(obj2.GetHashCode());//100900
Console.WriteLine(obj1.CompareTo(obj2)); //-1
Console.WriteLine(obj1.Equals(obj2));//false
//测试重载的运算符
Console.WriteLine(obj1 == obj2); //false
Console.WriteLine(obj1 != obj2); //true
Console.WriteLine(obj1 >= obj2); //false
//以下测试Circle对象数组的排序功能
Circle[] circles = new Circle[10]; //创建Circle对象数组
Random ran = new Random();
for (int i = 0; i < 10; i++)
{
circles[i] = new Circle { Radius = ran.Next(1, 1000)/100.0 };
}
Console.WriteLine("原始数组:");
Array.ForEach<Circle>(circles, (circle) => { Console.WriteLine("圆对象的哈希代码:{0},半径:{1}", circle.GetHashCode(), circle.Radius); });
Console.WriteLine("\n排序之后:");
Array.Sort(circles);
Array.ForEach<Circle>(circles, (circle) => { Console.WriteLine("圆对象的哈希代码:{0},半径:{1}", circle.GetHashCode(), circle.Radius); });
Console.ReadKey();
}