В созданном проекте, можно добавить класс, в отдельном файле, который сгенерирует Visual Studio.
Правой кнопкой мыши выделите проект. Add. New Item.
Правой кнопкой мыши выделите проект. Add. New Item.

Добавьте файл класса.

Visual Studio сгенерировало класс. Пространство имен соответствует имени проекта. При желании, его можно удалить. Так же можно изменить название класса.

Counter.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
_0001 {
-
class
Counter {
-
ushort
showStart;
-
ushort
showEnd;
-
decimal
price;
-
public
Counter(
ushort
arg0,
ushort
arg1,
decimal
arg2) {
-
showStart = arg0;
-
showEnd = arg1;
-
price = arg2;
-
}
-
public
ushort
ResultShow() {
-
return
(
ushort
)(showEnd-showStart);
-
}
-
public
decimal
Sum() {
-
return
Math.Round((
decimal
)(ResultShow()*price), 2);
-
}
-
}
}
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
_0001 {
-
class
Counter {
-
ushort
showStart;
-
ushort
showEnd;
-
decimal
price;
-
public
Counter(
ushort
arg0,
ushort
arg1,
decimal
arg2) {
-
showStart = arg0;
-
showEnd = arg1;
-
price = arg2;
-
}
-
public
ushort
ResultShow() {
-
return
(
ushort
)(showEnd-showStart);
-
}
-
public
decimal
Sum() {
-
return
Math.Round((
decimal
)(ResultShow()*price), 2);
-
}
-
}
}
Main.cs
using
System;
//подключить пространство имен
using
_0001;
class
Program {
-
public
static
int
Main() {
-
Console.WriteLine(
"оплата за электроэнергию\n"
);
-
Console.Write(
"Введите начальные показания счетчика : "
);
-
ushort
show_start =
ushort
.Parse(Console.ReadLine());
-
Console.Write(
"Введите конечные показания счетчика : "
);
-
ushort
show_end =
ushort
.Parse(Console.ReadLine());
-
Console.Write(
"Введите цену за 1 кВт/ч : "
);
-
decimal
price =
decimal
.Parse(Console.ReadLine());
-
Counter C =
new
Counter(show_start, show_end, price);
-
Console.WriteLine(
"Сумма за электроэнергию : {0}"
, C.Sum());
-
Console.ReadKey();
-
return
0;
-
}
}
using
System;
//подключить пространство имен
using
_0001;
class
Program {
-
public
static
int
Main() {
-
Console.WriteLine(
"оплата за электроэнергию\n"
);
-
Console.Write(
"Введите начальные показания счетчика : "
);
-
ushort
show_start =
ushort
.Parse(Console.ReadLine());
-
Console.Write(
"Введите конечные показания счетчика : "
);
-
ushort
show_end =
ushort
.Parse(Console.ReadLine());
-
Console.Write(
"Введите цену за 1 кВт/ч : "
);
-
decimal
price =
decimal
.Parse(Console.ReadLine());
-
Counter C =
new
Counter(show_start, show_end, price);
-
Console.WriteLine(
"Сумма за электроэнергию : {0}"
, C.Sum());
-
Console.ReadKey();
-
return
0;
-
}
}
оплата за электроэнергию
Введите начальные показания счетчика : 0
Введите конечные показания счетчика : 100
Введите цену за 1 кВт/ч : 0,3084
Сумма за электроэнергию : 30,84
Введите начальные показания счетчика : 0
Введите конечные показания счетчика : 100
Введите цену за 1 кВт/ч : 0,3084
Сумма за электроэнергию : 30,84