我想編譯和測試我的代碼作業我的作業,並且Visual Studio拋出錯誤說'對象'不包含方法'處置',我不明白爲什麼它不會讓我編譯我的代碼。分配如下:'對象'不包含'處置'的方法C#編譯器錯誤
矩形類:創建一個類矩形。該類具有屬性長度和寬度,每個屬性默認爲1.它具有隻讀屬性,可以計算矩形的周長和麪積。它具有長度和寬度的屬性。設置的訪問器應該驗證長度和寬度是每個大於0.0且小於20.0的浮點數。編寫一個應用程序來測試類Rectangle。
下面是Rectangle類的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApplication16
{
class Rectangle
{
private float length = 1;
private float width = 1;
public Rectangle(float length, float width)
{
Length = length;
Width = width;
}
public float Length
{
get
{
return this.length;
}
set
{
if (value <= 0.0f || value > 20.0f)
{
this.length = 1.0f;
}
else
{
this.length = value;
}
}
}
public float Width
{
get
{
return this.width;
}
set
{
if (value <= 0.0f || value > 20.0f)
{
this.width = 1.0f;
}
else
{
this.width = value;
}
}
}
public float Perimeter
{
get
{
return(Length + Width)*2;
}
}
public float Area
{
get
{
return(Length*Width);
}
}
public override string ToString()
{
return string.Format("Perimeter is {0:F2} and Area is {1:F2}", Perimeter, Area);
}
}
}
下面是應用測試代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApplication16
{
class TestProgram
{
static void main(string[] args)
{
Rectangle rect = new Rectangle(19.5f, 15.9f);
Console.WriteLine(rect);
Console.ReadLine();
}
}
}
當我去編譯它,它拋出了兩個錯誤:
Error 1 'WindowsFormsApplication16.Form2.Dispose(bool)': no suitable method found to
override c:\users\kyle\documents\visual studio 2012\Projects\WindowsFormsApplication16\
WindowsFormsApplication16\Form2.Designer.cs 14 33 WindowsFormsApplication16
Error 2 'object' does not contain a definition for 'Dispose'
c:\users\kyle\documents\visual studio 2012\Projects\WindowsFormsApplication16\
WindowsFormsApplication16\Form2.Designer.cs 20 18
WindowsFormsApplication16
這是它說的錯誤代碼位於:
namespace WindowsFormsApplication16
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
#endregion
}
}
任何人都可能闡明這一點,並給我一個想法,爲什麼它不會編譯?
最後一塊代碼。系統是否生成? –
@ChetanRanpariya是的,正如評論自己所說的。 – Servy
如果項目中不需要表單,那麼現在就可以刪除它,看看事情是否正常。如果只是形式或其他背後的東西,那麼你肯定會這麼做。 –