Home > Net >  C # interface implementation of the rectangular area calculation
C # interface implementation of the rectangular area calculation

Time:11-24

Why cannot display area, want to know where is wrong
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
Using System. The Threading. The Tasks;
The implementation of the namespace interface
{interface IShape
{int Length {get; set; }
Int Width {get; set; }
Void GetArea (); }
The class Test: IShape
{
Public int getarea ()
{return Length * Width; }
Public int chang {get; set; }
Public int kuan {get; set; }
Public int Length {get {return Length; } the set {Length=value; }
}
Public int Width
{
The get {return Width; }
The set {Width=value; }
}
Public void GetArea () {Console. WriteLine (" the area of the rectangle: {0} ", (chang * kuan)); }
Class Program {
The static void Main (string [] args) {
Console. WriteLine (" please enter the rectangular wide: "); The Console. ReadLine ();
Console. WriteLine (" please enter a long rectangular: "); The Console. ReadLine ();
The Test getarea=new Test (); Console. WriteLine (" the area of the rectangle: {0} ", getArea ()); The Convert. ToInt32 (Console. ReadLine ()); }}}}

CodePudding user response:

The content of the console input, use variables to receive

CodePudding user response:

reference 1st floor weixin_46600974 response:
console input content, use variables to receive

Can you say detailed point (novice don't know much about)

CodePudding user response:

The content of the Console input, use variable to receive the Console. WriteLine (" please enter the rectangular wide: "); The Console. ReadLine ();
Console. WriteLine (" please enter a long rectangular: "); The Console. ReadLine (); The place to be variable accept ah

CodePudding user response:

The Test getarea=new Test ();
Console. WriteLine (" please enter the rectangular wide: ");
Var widthStr=Console. ReadLine ();
while (! Int. J TryParse (widthStr, out getarea. Width))
{
Console. WriteLine (" the content of the input is not the integer, please enter the rectangular wide: ");
WidthStr=Console. ReadLine ();
}
Console. WriteLine (" please enter a long rectangular: ");
Var lengthStr=Console. ReadLine ();
while (! Int. J TryParse (lengthStr, out getarea. Length))
{
Console. WriteLine (" the content of the input is not the integer, please input rectangular long: ");
LengthStr=Console. ReadLine ();
}
Console. WriteLine (" the area of the rectangle: {0} ", getarea. Getarea ());
The Console. ReadLine ();

CodePudding user response:

refer to 6th floor weixin_46600974 response:
Test getarea=new Test ();
Console. WriteLine (" please enter the rectangular wide: ");
Var widthStr=Console. ReadLine ();
while (! Int. J TryParse (widthStr, out getarea. Width))
{
Console. WriteLine (" the content of the input is not the integer, please enter the rectangular wide: ");
WidthStr=Console. ReadLine ();
}
Console. WriteLine (" please enter a long rectangular: ");
Var lengthStr=Console. ReadLine ();
while (! Int. J TryParse (lengthStr, out getarea. Length))
{
Console. WriteLine (" the content of the input is not the integer, please input rectangular long: ");
LengthStr=Console. ReadLine ();
}
Console. WriteLine (" the area of the rectangle: {0} ", getarea. Getarea ());
The Console. ReadLine ();

The getArea error, "the implementation of the interface. The Test" does not contain the definition of "getArea", and couldn't find the acceptable type for "the implementation of the interface. The Test" of the first parameter of extension method getArea ""

CodePudding user response:

Repeat posts,

Your GetArea method must have a return type,
 

Interface IShape
{
Int Length {get; set; }
Int Width {get; set; }
Int GetArea ();//can't is a void method, needs to have a return type,
}
  •  Tags:  
  • C#
  • Related