develop

c# oracle in 과 같은 함수.

파드파드 2023. 11. 13. 11:28
반응형

 

Sol 1. 

public static bool In<T>(this T item, params T[] items)
{
if (items == null)
throw new ArgumentNullException("items");

return items.Contains(item);
}

 

1. 예)

int ix= 1;
if (ix.In(1, 2, 3))

string s1= "B";

if (s1.In("A", "B", "C")) 

 

 

Sol 2. 

public static bool In(object compare, params string[] sList) {
    for (int index = 0; index < sList.Length; ++index) {
        if (sList[index] == compare.ToString())
            return true;
    }
    return false;
}

반응형