Контроль вводимых данных в приложение - C#
Формулировка задачи:
Здравствуйте, пожалуйста помогите исправить ошибку в программе.
Мне нужно, чтобы при вводе оценок, например, если ввести любое слово или символ :в , выводилась ошибка.
За ранее всем спасибо.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StudentCons
{
class Program
{
public struct Student
{
public string fio;
public string numberGroup;
public string[] arr;
//arr = new int[5]; // create a 5 element integer array
}
static void Main(string[] args)
{
bool print = false;
Student [] st = new Student[10];
for (int i = 0; i < st.Count(); i++)
{
Console.Clear();
Console.WriteLine("Введите ФИО:");
st[i].fio= Console.ReadLine();
Console.WriteLine("Введите номер группы:");
st[i].numberGroup = Console.ReadLine();
st[i].arr= new string[5];
for (int j = 0; j < st[i].arr.Count(); j++)
{
Console.WriteLine("Введите оценку:");
st[i].arr[j] = Console.ReadLine();
}
}
foreach (var p in st.OrderBy(itm => itm.fio))
{
System.Diagnostics.Trace.WriteLine(p.fio);
}
Console.Clear();
foreach (var student in st)
{
foreach (var oc in student.arr)
{
if (oc == "2")
{
Console.WriteLine("Имя студента с оценкой 2 - " + student.fio + " Номер группы - " + student.numberGroup);
print = true;
break;
}
}
}
if (!print)
{
Console.WriteLine("Нету студентов с оценкой 2");
}
Console.ReadLine();
}
}
}Решение задачи: «Контроль вводимых данных в приложение»
textual
Листинг программы
int res;
while (!int.TryParse(Console.ReadLine(), out res)) {
Console.WriteLine("Wrong data!");
}