当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.GetArea方法代码示例

本文整理汇总了C#中Rectangle.GetArea方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.GetArea方法的具体用法?C# Rectangle.GetArea怎么用?C# Rectangle.GetArea使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rectangle的用法示例。


在下文中一共展示了Rectangle.GetArea方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

  public static void Main()
  {
    Rectangle myRectangle = new Rectangle();

    Console.WriteLine("Enter the length: ");
    string stringLength = Console.ReadLine();
    int myLength = int.Parse(stringLength);
    myRectangle.Length = myLength;

    Console.WriteLine("Enter the width: ");
    string stringWidth = Console.ReadLine();
    int myWidth = int.Parse(stringWidth);
    myRectangle.Width = myWidth;

    if (myRectangle.IsSquare())
    {
      Console.WriteLine("Congratulations! You made a square!");
    } 
    else 
    {
      Console.WriteLine("Sorry! This isn't a square.");
    }

    Console.WriteLine("The area of your rectangle is " + myRectangle.GetArea());
  }
开发者ID:nlarion,项目名称:cSharpPractice,代码行数:25,代码来源:Rectangle.cs

示例2: 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());
        }
开发者ID:agicheva,项目名称:Programming-101-CSharp,代码行数:56,代码来源:GeometryFigure.cs

示例3: AreaSimilarity

		public AreaSimilarity(Rectangle queryExtent, double queryPower, double targetPower)
		{
			this.queryExtent = queryExtent;
			this.queryArea = queryExtent.GetArea(null);

			this.queryPower = queryPower;
			this.targetPower = targetPower;

			//  if (this.qryMinX > queryExtent.getMaxX()) {
			//    this.qryCrossedDateline = true;
			//    this.qryArea = Math.abs(qryMaxX + 360.0 - qryMinX) * Math.abs(qryMaxY - qryMinY);
			//  } else {
			//    this.qryArea = Math.abs(qryMaxX - qryMinX) * Math.abs(qryMaxY - qryMinY);
			//  }
		}
开发者ID:raol,项目名称:lucene.net,代码行数:15,代码来源:AreaSimilarity.cs

示例4: Area

 public override double Area(Rectangle rect)
 {
     return rect.GetArea(null);
 }
开发者ID:ccurrens,项目名称:Spatial4n,代码行数:4,代码来源:CartesianDistCalc.cs

示例5: Score

		public double Score(Rectangle target, Explanation exp)
		{
			if (target == null || queryArea <= 0)
			{
				return 0;
			}
			double targetArea = target.GetArea(null);
			if (targetArea <= 0)
			{
				return 0;
			}
			double score = 0;

			double top = Math.Min(queryExtent.GetMaxY(), target.GetMaxY());
			double bottom = Math.Max(queryExtent.GetMinY(), target.GetMinY());
			double height = top - bottom;
			double width = 0;

			// queries that cross the date line
			if (queryExtent.GetCrossesDateLine())
			{
				// documents that cross the date line
				if (target.GetCrossesDateLine())
				{
					double left = Math.Max(queryExtent.GetMinX(), target.GetMinX());
					double right = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
					width = right + 360.0 - left;
				}
				else
				{
					double qryWestLeft = Math.Max(queryExtent.GetMinX(), target.GetMaxX());
					double qryWestRight = Math.Min(target.GetMaxX(), 180.0);
					double qryWestWidth = qryWestRight - qryWestLeft;
					if (qryWestWidth > 0)
					{
						width = qryWestWidth;
					}
					else
					{
						double qryEastLeft = Math.Max(target.GetMaxX(), -180.0);
						double qryEastRight = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
						double qryEastWidth = qryEastRight - qryEastLeft;
						if (qryEastWidth > 0)
						{
							width = qryEastWidth;
						}
					}
				}
			}
			else
			{ // queries that do not cross the date line

				if (target.GetCrossesDateLine())
				{
					double tgtWestLeft = Math.Max(queryExtent.GetMinX(), target.GetMinX());
					double tgtWestRight = Math.Min(queryExtent.GetMaxX(), 180.0);
					double tgtWestWidth = tgtWestRight - tgtWestLeft;
					if (tgtWestWidth > 0)
					{
						width = tgtWestWidth;
					}
					else
					{
						double tgtEastLeft = Math.Max(queryExtent.GetMinX(), -180.0);
						double tgtEastRight = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
						double tgtEastWidth = tgtEastRight - tgtEastLeft;
						if (tgtEastWidth > 0)
						{
							width = tgtEastWidth;
						}
					}
				}
				else
				{
					double left = Math.Max(queryExtent.GetMinX(), target.GetMinX());
					double right = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
					width = right - left;
				}
			}


			// calculate the score
			if ((width > 0) && (height > 0))
			{
				double intersectionArea = width * height;
				double queryRatio = intersectionArea / queryArea;
				double targetRatio = intersectionArea / targetArea;
				double queryFactor = Math.Pow(queryRatio, queryPower);
				double targetFactor = Math.Pow(targetRatio, targetPower);
				score = queryFactor * targetFactor * 10000.0;

				if (exp != null)
				{
					//        StringBuilder sb = new StringBuilder();
					//        sb.append("\nscore=").append(score);
					//        sb.append("\n  query=").append();
					//        sb.append("\n  target=").append(target.toString());
					//        sb.append("\n  intersectionArea=").append(intersectionArea);
					//        
					//        sb.append(" queryArea=").append(queryArea).append(" targetArea=").append(targetArea);
//.........这里部分代码省略.........
开发者ID:raol,项目名称:lucene.net,代码行数:101,代码来源:AreaSimilarity.cs

示例6: 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

//.........这里部分代码省略.........
开发者ID:claudiu-orosanu,项目名称:Fundamentals2016,代码行数:101,代码来源:Program.cs


注:本文中的Rectangle.GetArea方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。