Home > Net >  A great god for help!!!!!!
A great god for help!!!!!!

Time:11-24

"Interface implementation to calculate rectangular area", would like to know how to change this code (request output in figure 1, is my figure 2)
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 chang {get; set; }
Public int kuan {get; set; }

Public int Length
{
The 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: ");
Var widthStr=Console. ReadLine (); Console. WriteLine (" please enter a long rectangular: ");
Var lengthStr=Console. ReadLine ();

The Test getArea=new Test (); Console. WriteLine (" the area of the rectangle: {0} ", getArea ()); The Console. ReadLine (); The Convert. ToInt32 (Console. ReadLine ()); }
}
}
}

CodePudding user response:

The Test getArea=new Test () {chang=int. Parse (lengthStr), kuan=int. J Parse (widthStr)}};
GetArea. GetArea ();

CodePudding user response:

reference 1st floor Bridge_go response:
Test getArea=new Test () {chang=int. Parse (lengthStr), kuan=int. Parse (widthStr)}};
GetArea. GetArea ();

This I can't, getArea error

CodePudding user response:

GetArea method needs a return value, you can't be a void type, such as:
 

Interface IShape
{
Int Length {get; set; }
Int Width {get; set; }
Int GetArea (); }

,,,

Public int GetArea ()
{
//the Console. WriteLine (" the area of the rectangle: {0} ", chang * kuan);
Return kuan chang *;
}


Console. WriteLine (" the area of the rectangle: {0} ",,,,
The {0} here can't preach a void type of method, need a return type and the method of value,
  •  Tags:  
  • C#
  • Related