c# - Best way to test if a Type is a collection -


I have a method that accepts the parameter obj type of system. Object

Now I want to know whether the actual type is obj:

  • A collection type (IEnumerable).
  • Anything else

The first method I have thought of:

  if obj is (isnumerable) // obj is a collection  

But System.String implements IEnumerable, and I do not want to treat string as a collection .

The way I thought it was a test for icocolon instead of ininmereble, because IEnumerable is more than a possible archive, a real one leaves this string out, but it also shows Icon-Off-T This is because it does not inherit IClippin (the nominal cable T-T is only compatible with the general collection abstraction that is compatible with the rear - it receives the INIMRAMABLE).

So I think the best way is this:

  if (obj string is) // if there is no archive (oz is IEnumerable) // archive th / No collections  

Is there a better way?

I think you are making it a bit confusing. If you really want to use IEnumerable, but leave the system. String, why not directly into the code?

Public Stable Bull Isylation (Object OBJE) {Reserve Obje Inimarable & amp; ! (Obj is string); }

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -