Ввести с клавиатуры значения - C#
Формулировка задачи:
Как сделать в данном примере, чтобы Number и num модно было вводить с клавиатуры несколько раз, пока пользователь не введёт ноль?
using System;
namespace ProgrammingGuide
{
// Class definition.
public class CustomClass
{
// Class members.
//
// Property.
public int Number { get; set; }
// Method.
public int Multiply(int num)
{
return num * Number;
}
// Instance Constructor.
public CustomClass()
{
Number = 0;
}
}
// Another class definition that contains Main, the program entry point.
class Program
{
static void Main(string[] args)
{
// Create an object of type CustomClass.
CustomClass custClass = new CustomClass();
// Set the value of the public property.
custClass.Number = 27;
// Call the public method.
int result = custClass.Multiply(4);
Console.WriteLine($"The result is {result}.");
}
}
}
// The example displays the following output:
// The result is 108.Решение задачи: «Ввести с клавиатуры значения»
textual
Листинг программы
static void Main(string[] args)
{
// Create an object of type CustomClass.
CustomClass custClass = new CustomClass();
do
{
Console.Write("Enter a digit: ");
custClass.Number = int.Parse(Console.ReadLine());
int result = custClass.Multiply(4);
Console.WriteLine($"The result is {result}.");
}
while (custClass.Number != 0);
}