2017-01-17 8 views
-2

私は宿題のコードをコンパイルしてテストしようとしていますが、Visual Studioでは 'オブジェクト'メソッドを 'dispose'にすると、なぜ私のコードをコンパイルできないのか分かりません。割り当ては次のようになります。'Object'に 'dispose'のメソッドが含まれていません。C#コンパイラエラー

Rectangleクラス:クラスRectangleを作成します。クラスには属性lengthとwidthがあり、それぞれデフォルトは1です。これは、矩形の周囲と面積を計算する読み取り専用プロパティを持ちます。それは長さと幅の両方のプロパティを持っています。設定されたアクセサは、長さと幅がそれぞれ0.0より大きく20.0より小さい浮動小数点数であることを検証する必要があります。テストクラス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(); 
     } 
    } 
} 

私はそれをコンパイルするために行くとき、それは2を投げますエラー:

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 
    } 
} 

誰もがこれについていくつか光を当てて、なぜ私はそれがコンパイルされないかというアイデアを与えることができますか?

+0

最後のコードブロック。それはシステム生成ですか? –

+0

@ChetanRanpariyaはい、コメント自体が言っています。 – Servy

+0

プロジェクトでフォームが不要な場合は、今すぐフォームを削除して、問題なく機能しているかどうかを確認できます。あなたが物事を崩す背後にあるのか、それともフォームのものなのかを確かめるでしょう。 –

答えて

0

Form2はクラスから派生する必要があります...私はそれが "Form"であるべきだと思います。新しいプロジェクトを作成する/新しいフォームを追加し、それが派生するクラスを表示します。あなたはたぶんそれを偶然削除しました。

+0

これは部分的なクラスです。基本クラスは他のファイルで定義されています。 – Servy

-1

最近、プロジェクトにフォームをインポートしていたときにこのエラーが発生しました。

フォームをインポートした後にエラーが発生しました。main.csコードファイルの名前空間を変更しましたが、対応するdesigner.csファイルの名前空間は変更しませんでした。名前空間にマッチすると、エラーメッセージが消えてしまいました。

関連する問題