简体   繁体   中英

How do I translate this dynamic collection expression from VB.NET into C#?

I have this very succinct expression in vb.NET which makes it easy to test to see if a value is in a list of known string literals but I don't know how to translate it to C#. (It is made all the more difficult because I cannot search for it knowing exactly how to describe what the name of this type of expression is)

Dim test as String = "test"
If {"test", "test2"}.Contains(test) Then

End If

You can use:

if (new [] {"test1, test2"}.Contains(test)) {
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM