온라인에서 찾고있는 것을 실제로 찾을 수 없기 때문에 질문하고 싶었습니다. IdNum
예를 들어 학생이 이미 존재 하는지 확인하고 싶습니다 .
Google 검색을 위해 찾고있는 올바른 용어를 모르겠습니다. 제가 가지고있는 책은 이런 종류의 확인을해야 할 때 무엇을해야하는지에 대해 그다지 유용하지 않습니다.
지금까지 시도한 코드는 다음과 같습니다.
static void Main(string[] args)
{
Class1[] c1 = new Class1[10]
for (int i = 0; i < c1.Length; i++)
{
Console.WriteLine("enter Student ID");
string text = Console.ReadLine();
int value;
while (!Int32.TryParse(text, out value))
{
Console.WriteLine("ID Was not a Valid ID Number. Try Again");
text = Console.ReadLine();
}
// maybe here say if IdNum exist or not
{
// Try a different number
}
}
}
Class Class1
{
public int IdNum { get; set; }
public int SomethingElse { get; set; }
// and so on
}
감사
IEnumerable<Class1> c1 = GetStudents();
string text = Console.ReadLine();
int value;
while (!Int32.TryParse(text, out value))
{
Console.WriteLine("ID Was not a Valid ID Number. Try Again");
text = Console.ReadLine();
}
bool exist = c1.Any(s = > s.IdNum == value);
linq를 사용하지 않으려면 다음과 같이 마지막 줄을 다시 작성할 수 있습니다.
bool exist = false;
foreach (var s in c1)
{
if (s.IdNum == value)
{
exist = true;
break;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다