本文整理汇总了C#中Rectangle.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.ToString方法的具体用法?C# Rectangle.ToString怎么用?C# Rectangle.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rectangle
的用法示例。
在下文中一共展示了Rectangle.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Point A = new Point(3.0, 4.0);
Point B = new Point(A);
Point C = new Point(3.0, 5.0);
Point D = new Point();
Console.WriteLine(A.ToString());
Console.WriteLine(B.ToString());
Console.WriteLine(C.ToString());
Console.WriteLine(D.ToString());
Console.WriteLine(A.Equals(B));
Console.WriteLine(B.Equals(C));
Console.WriteLine(A == B);
Console.WriteLine(A == C);
LineSegment line1 = new LineSegment(A, C);
LineSegment line2 = new LineSegment(D, A);
Console.WriteLine(line1.Equals(line2));
Console.WriteLine(line1 == line2);
Console.WriteLine(line1.ToString());
Console.WriteLine(line1 > line2);
Console.WriteLine(line2 >= 3.0);
Point left = new Point(1, 1);
Point right = new Point(7, 5);
Point c = new Point(4, 3);
Rectangle rect1 = new Rectangle(left, right);
Rectangle rect2 = new Rectangle(c, right);
Rectangle rect3 = new Rectangle(rect1);
Console.WriteLine(rect3.ToString());
Console.WriteLine(rect1.GetPerimeter());
Console.WriteLine(rect1.GetArea());
Console.WriteLine(rect1.Equals(rect2));
Console.WriteLine(rect1.Equals(rect3));
Console.WriteLine(rect1.Center.ToString());
Console.WriteLine(rect1 == rect2);
Console.WriteLine(rect2 != rect3);
Vector v1 = new Vector(1, 3, 5);
Vector v2 = new Vector(2, 4, 6);
Vector v3 = new Vector(v1);
double num = 5;
Console.WriteLine(v1.ToString());
Console.WriteLine(v1.Equals(v2));
Console.WriteLine(v1.Equals(v3));
Console.WriteLine((v1 + v2).ToString());
Console.WriteLine((v2 - v1).ToString());
Console.WriteLine((v1 * v2).ToString());
Console.WriteLine((v1 / v2).ToString());
Console.WriteLine((v1 + num).ToString());
}
示例2: Form1
//By James Palmisano
//last edited 1/30/14
//Extend the previous Shape program to include one
//data structure (like an array) that is capable of holding
//both Circles and Rectangles. Use a for each loop to loop
//through the data structure and display the area.
//Purpose of app is to show inheritance.
public Form1()
{
//declair array
Shape[] shapes;
shapes = new Shape[2];
shapes[1] = new Rectangle();
shapes[2] = new Circle();
InitializeComponent();
//make instance of rectangle class
Rectangle rect = new Rectangle();
rectangleInfo.Text = rect.ToString();
areaOfRectangle.Text = "The area of the rectangle is: "
+ Convert.ToString(decimal.Round
(Convert.ToDecimal(rect.Area), 2, MidpointRounding.AwayFromZero));
//make instance of the circle class
Circle cir = new Circle();
circleInfo.Text = cir.ToString();
circleArea.Text = "The area of the circle is: "
+ Convert.ToString(decimal.Round
(Convert.ToDecimal(cir.Area), 2, MidpointRounding.AwayFromZero));
}
示例3: RectangleToStringAndFromString
public void RectangleToStringAndFromString()
{
var rect = new Rectangle(2.12f, 2.12f, 1.12f, 1.12f);
string rectString = rect.ToString();
Assert.AreEqual(rect, new Rectangle(rectString));
Assert.Throws<Rectangle.InvalidNumberOfComponents>(() => new Rectangle("abc"));
}
示例4: RectangleToString
public void RectangleToString()
{
var p = new Point(2f, 2f);
var s = new Size(1f, 1f);
var rect = new Rectangle(p, s);
Assert.AreEqual("2 2 1 1", rect.ToString());
}
示例5: Main
// the entry point for all C# programs. The Main method states what the class does when executed.
static void Main(string[] args)
{
#region part2 - class, namespace, dynamic type, static methodes, convertions, constant, readonly, struct, generics, enums
Console.WriteLine("\n\n\nPart 2: \n");
#region simple class example
// initialization methods:
// 1:
var rectangle1 = new Rectangle
{
Length = 10,
Width = 6
};
// 2:
var rectangle2 = new Rectangle(12, 8);
// 3:
var rectangle3 = new Rectangle();
rectangle3.InitializeWithCustomValues();
// 4:
var rectangle4 = new Rectangle();
rectangle4.InitializeWithSpecificValues(20, 15);
// call methods:
Console.WriteLine(rectangle1.GetArea());
rectangle1.Display();
Console.WriteLine(rectangle1.ToString());
Console.ReadKey();
Console.WriteLine(rectangle2.ToString());
Console.ReadKey();
Console.WriteLine(rectangle3.ToString());
Console.ReadKey();
Console.WriteLine(rectangle4.ToString());
Console.ReadKey();
// to do: GetPerimeter();
#endregion
#region namespace example
Test3.MyMethode();
#endregion
#region satatic class, static methods, dynamic type example
// dinamyc type: (with static class, static methode)
Console.WriteLine();
DynamicTypes.DynamicTypesExample();
#endregion
#region var, boxing and unboxing, conversion
var val = 1;
object obj = val; // boxing;
int i = (int)obj; // unboxing;
// cast double to int.
double nr1 = 5673.74;
int nr2 = (int) nr1;
Console.WriteLine("nr = {0}, type = {1}", nr1, nr1.GetType());
Console.WriteLine("nr = {0}, type = {1}", nr2, nr2.GetType());
Console.ReadKey();
#endregion
#region const, readonly
// working with constants:
Console.WriteLine("\n");
Console.WriteLine("Enter Radius: ");
try
{
var radius = Convert.ToDouble(Console.ReadLine());
var circle = new CircleExampleWithConstants(radius);
circle.DisplayArea();
}
catch (FormatException e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
#endregion
// struct
// generic types
// enums
// extension methods
//.........这里部分代码省略.........
示例6: ToStringTest
public void ToStringTest(int x, int y, int width, int height)
{
var r = new Rectangle(x, y, width, height);
Assert.Equal(string.Format(CultureInfo.CurrentCulture, "{{X={0},Y={1},Width={2},Height={3}}}", r.X, r.Y, r.Width, r.Height), r.ToString());
}
示例7: Main
static void Main(string[] args)
{
MethodInfo[] ms = typeof(object).GetMethods();
foreach (MethodInfo m in ms)
{
Console.WriteLine(m.ToString());
}
Console.WriteLine(FiboCalculator.Equals(10, 0.0));
Console.WriteLine("***Fun With Conversions ***");
int myInt = 12345678;
myInt.DisplayDefiningAssembly();
System.Data.DataTable dt = new System.Data.DataTable();
dt.DisplayDefiningAssembly();
Console.WriteLine( myInt.ReverseDigits());
Console.WriteLine("扩展接口测试");
string[] data = { "Wow", "this", "is ", "sort", "of", "annoying", "but", "in", "a", "weird", "way", "fun" };
data.PrintDataAndBeep();
Rectangle r=new Rectangle(5,4);
Console.WriteLine(r.ToString());
r.Draw();
Square s = (Square)r;
Console.WriteLine(s.ToString());
s.Draw();
Console.WriteLine(GC.GetTotalMemory(false)+"---"+GC.MaxGeneration);
// Console.ReadLine();
BuildAnonType("BWM", "red", 1234);
}