0
문자열이 목록으로 전달되었는지 확인하는 C#의 메서드를 만들려고합니다.문자열이 목록에 전달되었는지 확인하는 방법
private List<string> _identifiers;
public Profile (string[] names)
{
_identifiers = new List<string>(names);
}
public bool Exists (string id)
{
if ((_identifiers [0] == "id1")&&(_identifiers [1] == "id2"))
{
return true;
}
else
{
return false;
}
}
어떻게하면됩니까? 감사!
음,'_identifiers.Contains (ID)'? (현재의 코드는'id'를 전혀 사용하지 않으며, 단지'_identifiers'의 처음 두 값만을 검사합니다. 이상하게 보입니다 ...'if (...) return true; 그렇지 않으면 false를 반환한다.'return ...'을 사용할 수있다. –