本文整理汇总了C#中Shape.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.CompareTo方法的具体用法?C# Shape.CompareTo怎么用?C# Shape.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shape
的用法示例。
在下文中一共展示了Shape.CompareTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckPosition
/// Method Check position - I accept Main area consist of invisible Shape elements
public void CheckPosition(Shape elementTopBar, Shape elementMainArea)
{
if (elementTopBar.CompareTo(elementMainArea) == 0)
{
this.Update(elementTopBar, elementMainArea);
}
else
{
this.livesCount--;
if (this.livesCount == 0)
{
this.State = GameState.Lose;
}
}
}
示例2: compareEllips
private static void compareEllips(Shape obj, Shape obje)
{
obj.CompareTo(obje);
}
示例3: Main
//.........这里部分代码省略.........
break;
case ConsoleKey.R:
Shape newRectangle = CreateShape(ShapeType.Rectangle);
Console.WriteLine("\nStep 1. Write the length of the rectangle:\nStep 2. Press enter \nStep 3. Write the width of the rectangle: ");
try
{
readLengthAndWidth(out currentLength, out currentWidth);
}
catch (FormatException e)
{
Console.WriteLine("Error: " + e.Message + " Write numbers.\n");
}
catch(Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
newRectangle.Length = currentLength;
newRectangle.Width = currentWidth;
ViewShapeInfo(newRectangle);
Console.WriteLine("Press enter");
savedRectangle = newRectangle;
Console.ReadKey();
break;
case ConsoleKey.S:
var resizeRectangle = CreateShape(ShapeType.ResizableRectangle);// as ResizableRectangle;
Console.WriteLine("\nStep 1. Write the length of the rectangle:\nStep 2. Press enter \nStep 3. Write the width of the rectangle:\nStep 4. Write how many percent you wish to resize with ");
try
{
readLengthAndWidth(out currentLength, out currentWidth);
}
catch (FormatException e)
{
Console.WriteLine("Error: " + e.Message);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
resizeRectangle.Length = currentLength;
resizeRectangle.Width = currentWidth;
ViewShapeInfo(resizeRectangle);
try
{
int percent = Int32.Parse(Console.ReadLine());
IResizable r = resizeRectangle as IResizable;
r.resize(percent);
ViewShapeInfo(resizeRectangle);
Console.ReadKey();
}
catch (FormatException e)
{
Console.WriteLine("Error: " + e.Message);
}
break;
case ConsoleKey.C:
Console.WriteLine("\nIf you got 1 your Ellips is bigger than your Rectangle\nIf you got -1 your rectangle is bigger than your Ellips\nIf you got a 0 they were the same");
try
{
Console.WriteLine(savedEllips.CompareTo(savedRectangle));
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("\nError: " + ex.Message + ", you need to create your Ellips and Rectangle before comparing them");
Console.ReadKey();
}
break;
case ConsoleKey.J:
Console.WriteLine("\nIf you got 1 your Rectangle is bigger than your Ellips\nIf you got - 1 your Ellips is bigger than your Rectangle\nIf you got a 0 they were the same");
try
{
Console.WriteLine(savedRectangle.CompareTo(savedEllips));
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("\nError: " + ex.Message + "\nYou need to create your Ellips and Rectangle before comparing them");
Console.ReadKey(); }
Console.ReadKey();
break;
case ConsoleKey.Escape:
start = false;
break;
}
}
}