From: Armin Zingler on
Am 28.06.2010 17:28, schrieb Mr. X.:
> If this is the only solution, so I shall manage it.
> but it seems too complicated writing this on code - it's a basic thing.
> Each time I need this I shall write "
> if (new list(of integer)(New integer(){1,2,5,18,13}).contains(a) ...

- You only have to create the list once. (At design time as well as at run time).
- You can make the same list accessible from different locations.


--
Armin
From: Phill W. on
On 28/06/2010 16:28, Mr. X. wrote:
> If this is the only solution, so I shall manage it.
> but it seems too complicated writing this on code - it's a basic thing.

"Basic" to you and I, perhaps, but how would Our Friends in Redmond set
about implementing it as a Framework class?

It would be some sort of "Set" class that you could create based on a
given list of values.
Then it would have to have a Contains method (or Intersection, if this
is a Set).
Then, and this is the "Fun" part, it would have to be a Generic template
so that it could be used with objects of /any/ Type.

It's turning into a mini project all of its own.

YMMV, but I've often written my own methods for this sort of thing,
along the lines of:

Function IsIn( _
ByVal iValue As Integer _
, ByVal ParamArray iList As Integer() _
) As Boolean
For Each iEach As Integer In iList
If iEach = iValue Then
Return True
End If
Next
Return False
End Function

? IsIn( a, 1, 2, 5, 18, 13 )

HTH,
Phill W.
From: Tom Shelton on
Phill W. expressed precisely :
> On 28/06/2010 16:28, Mr. X. wrote:
>> If this is the only solution, so I shall manage it.
>> but it seems too complicated writing this on code - it's a basic thing.
>
> "Basic" to you and I, perhaps, but how would Our Friends in Redmond set about
> implementing it as a Framework class?
>
> It would be some sort of "Set" class that you could create based on a given
> list of values.
> Then it would have to have a Contains method (or Intersection, if this is a
> Set).


IEnumerable(Of T) already has an Intersect, Union, and Except as
Extension methods.


--
Tom Shelton


From: J.B. Moreno on
In article <#0uDluVFLHA.4504(a)TK2MSFTNGP02.phx.gbl>, Mr. X.
<nospam(a)nospam_please.com> wrote:

> What I meant is :
> dim a as integer
> ...
> a = 3
>
> What should I do instead of :
> if a = 1 or a = 2 or a = 5 or a = 18 or a = 33
> The pseudo code for short solution is :
> if a in (1,2,5,18,33) ...
> but the above does't work in VB.NET.
> What should I write instead of above ?

The problem is that VB (and C#) doesn't have the concept of a set as a
base type, the FRAMEWORK has collections, but until 2010 VB didn't have
a simple collection initializer (which means that you couldn't leverage
that into what you want).

With VB.2010 you can do this:

array.IndexOf({1,2,5,18,33}, a) > -1

and it works (although an extension method would be much clearer).


(And why, why, is IndexOf a SHARED mehod instead of an instance method?
{1,2,5, 18, 23}.IndexOf(a) > -1 would almost be clear enough that you
wouldn't need an extension method).

--
J.B. Moreno