Home > Net >  A constructor
A constructor

Time:05-27

using System;
using System.Collections.Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace class method 3
{

Class Program
{

Public static void Main (string [] args)
{
Int length=0;
Int width=0;
Console. WriteLine (" please enter the length and width ");
Length=Console. The Read ();
Width=Console. The Read ();
Rectangle r=new rectangle (length, width);
R.m ianji ();
R.z houchang ();


The Console. ReadKey ();
}

}
Public class rectangle
{
Int c=0;
Int s=0;
Public int Length
{
The get;
set;
}

Public int Width
{
The get;
set;

}
The public a rectangle (int length, int width)
{
This. Length=Length;
This. Width=Width;
}


Public void mianji ()
{
C=(Length + Width) * 2;

Console. WriteLine (" circumference is "+ c);
}
Public void zhouchang ()
{
S=(Length) * (Width);
Is the size of the Console. WriteLine (" "+ s);
}

}
}

Why the keyboard playing number and input do not match the number of procedures?















CodePudding user response:

 
The static void Main (string [] args)
{
Int length=0;
int width=0;
Console. WriteLine (" please enter the length and width ");
Length=int. Parse (Console. ReadLine ());
Width=int. Parse (Console. ReadLine ());
Rectangle r=new rectangle (length, width);
R.m ianji ();
R.z houchang ();


The Console. ReadKey ();
}

CodePudding user response:

Attention should be paid to int and string conversion between

CodePudding user response:

refer to the second floor taocl2000 response:
note int and string conversion between

Why run shows the format of the input string is wrong
  •  Tags:  
  • C#
  • Related