当前位置:编程学习 > C#/ASP.NET >>

小题

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


这是怎么回事 --------------------编程问答-------------------- System.Drawing --------------------编程问答--------------------
using System.Drawing;
--------------------编程问答-------------------- using System.Drawing; --------------------编程问答-------------------- 好像不对啊:命名空间“System”中不存在类型或命名空间名称“Darwing”(是缺少程序集引用吗?) --------------------编程问答-------------------- 源代码:
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();

        }
    }
} --------------------编程问答-------------------- 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();

   }
   }
} --------------------编程问答-------------------- 添加对system.drawing.dll的引用 --------------------编程问答-------------------- @6楼
   呵呵 --------------------编程问答-------------------- 引用问题
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,