static void Main(string[] args)
        {
            List<Rectangle> list = new List<Rectangle>();
            
            foreach (Rectangle rectangle in list)
找不到类型或命名空间名称“Rectangle”(是否缺少 using 指令或程序集引用?)
这是怎么回事

解决方案 »

  1.   

    好像不对啊:命名空间“System”中不存在类型或命名空间名称“Darwing”(是缺少程序集引用吗?)
      

  2.   

    源代码:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Darwing;namespace ConsoleApplication3
    {
        class Program
        {
            public int Length { get; set; }
            public int Width { get; set; }
            public int A { get; set; }
            public int B { get; set; }
            static void Main(string[] args)
            {
                List<Rectangle> list = new List<Rectangle>();
                list.Add(new Rectangle() { Length = 1, Width = 2, A = 0, B = 2 });
                list.Add(new Rectangle() { Length = 4, Width = 2, A = 5, B = 9 });
                list.Add(new Rectangle() { Length = 6, Width = 1, A = 3, B = 7 });
                list.Add(new Rectangle() { Length = 7, Width = 13, A = 1, B = 2 });
                list.Add(new Rectangle() { Length = 9, Width = 5, A = 10, B = 12 });
                list.Add(new Rectangle() { Length = 6, Width = 4, A = 4, B = 5 });            foreach (Rectangle rectangle in list)
                {
                    if (rectangle.Width > rectangle.Length)
                    {
                        int temp = rectangle.Width;
                        rectangle.Width = rectangle.Length;
                        rectangle.Length = temp;
                    }
                }
                int j = 5;
                var result = from rectangle in list where rectangle.A <= j && rectangle.B >= j orderby rectangle.B - j == 0 ? (rectangle.B - j) : rectangle.Length - rectangle.Length + 1, rectangle.Length descending, rectangle.Width descending select rectangle;
                foreach (var obj in result)
                {
                    Console.WriteLine(string.Format("Length:{0} Width:{1} A:{2} B:{3}", obj.Length, obj.Width, obj.A, obj.B));
                }
                Console.ReadKey();        }
        }
    }
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication3
    {
       class Rectangle
       {
       public int Length { get; set; }
       public int Width { get; set; }
       public int A { get; set; }
       public int B { get; set; }
       static void Main(string[] args)
       {
       List<Rectangle> list = new List<Rectangle>();
       list.Add(new Rectangle() { Length = 1, Width = 2, A = 0, B = 2 });
       list.Add(new Rectangle() { Length = 4, Width = 2, A = 5, B = 9 });
       list.Add(new Rectangle() { Length = 6, Width = 1, A = 3, B = 7 });
       list.Add(new Rectangle() { Length = 7, Width = 13, A = 1, B = 2 });
       list.Add(new Rectangle() { Length = 9, Width = 5, A = 10, B = 12 });
       list.Add(new Rectangle() { Length = 6, Width = 4, A = 4, B = 5 });   foreach (Rectangle rectangle in list)
       {
       if (rectangle.Width > rectangle.Length)
       {
       int temp = rectangle.Width;
       rectangle.Width = rectangle.Length;
       rectangle.Length = temp;
       }
       }
       int j = 5;
       var result = from rectangle in list where rectangle.A <= j && rectangle.B >= j orderby rectangle.B - j == 0 ? (rectangle.B - j) : rectangle.Length - rectangle.Length + 1, rectangle.Length descending, rectangle.Width descending select rectangle;
       foreach (var obj in result)
       {
       Console.WriteLine(string.Format("Length:{0} Width:{1} A:{2} B:{3}", obj.Length, obj.Width, obj.A, obj.B));
       }
       Console.ReadKey();   }
       }
    }