VB.NET - 替代Array.Contains? [英] VB.NET - Alternative to Array.Contains?
问题描述
在,我用这个上的.NET Framework 3.5和它的正常工作:
Before, I use this on .NET Framework 3.5 and it's working fine:
If (New String() {"ER", "PM", "EM", "OC"}).Contains(Session("Position")) Then
'Some codes
End If
现在我做的,与.NET 2.0及以上code未运行工作的一个项目,它给了我这样的:
Now I am doing a project that runs with .NET 2.0 and the code above is not working, it's giving me this:
'Contains' is not a member of 'System.Array'.
我怎样才能达到codeS上面(。载)不迁移从2.0到3.0吗?任何替代方案?
How can I achieve the codes above (.Contains) without migrating from 2.0 to 3.0? Any alternatives?
推荐答案
您将不得不重写你的code,像这样......
You will have to rewrite your code, like so...
If (Array.IndexOf(New String() {"ER", "PM", "EM", "OC"}), Session("Position")>-1) Then
'Some codes
End If
该集合初始化是依赖于编译器,而不是框架对象而定,所以这应该工作。
The collection initializer is depends on the compiler, but not the framework being targetted, so this should work.
编辑:固定错误的方法/条件。我得到了interupted与作为我工作的这一点,并不意味着将它张贴,直到我已经证实了它的工作原理漏水下沉。
fixed wrong method/ condition. I got interupted with a leaky sink as I was working on this, and didn't mean to post it until I'd verified that it works.
这篇关于VB.NET - 替代Array.Contains?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!