473,411 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

IsArray?

Hello again,

I've got a type variable, e.g.

Type type;

Now I want to know whether the type represents an Array type
(System.Array).

type.IsArray results false because System.Array is an object, not an
array.

How can I find out, whether the type variable represents System.Array?

The way type.Name == "System.Array" is not really good, isn't it?

Norbert
Jun 27 '08 #1
8 6424
"Norbert Pürringer" <th*******@graffiti.netwrote:
The way type.Name == "System.Array" is not really good, isn't it?
typeof(Array).IsAssignableFrom(type)

Eq.
Jun 27 '08 #2
On Apr 28, 12:07 pm, Norbert Pürringer <thalio...@graffiti.netwrote:
I've got a type variable, e.g.

Type type;

Now I want to know whether the type represents an Array type
(System.Array).

type.IsArray results false because System.Array is an object, not an
array.
What exactly do you mean by that? type.IsArray should be fine.

Could you post a short but complete program demonstrating the problem?

Jon
Jun 27 '08 #3
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote:
What exactly do you mean by that? type.IsArray should be fine.
typeof(anything[]).IsArray is true, but typeof(Array).IsArray is false.

Eq.
Jun 27 '08 #4
On Apr 28, 1:39 pm, "Paul E Collins" <find_my_real_addr...@CL4.org>
wrote:
"Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
What exactly do you mean by that? type.IsArray should be fine.

typeof(anything[]).IsArray is true, but typeof(Array).IsArray is false.
As the docs (for IsArray) state: "The Array class returns false
because it is not an array."

Not exactly clear, but my guess is it's because Array is abstract -
you can't have an instance of just Array, and various array-like
things don't make sense for it (such as element type).

Jon
Jun 27 '08 #5
Norbert Pürringer wrote:
Hello again,

I've got a type variable, e.g.

Type type;

Now I want to know whether the type represents an Array type
(System.Array).

type.IsArray results false because System.Array is an object, not an
array.

How can I find out, whether the type variable represents System.Array?
Could to not see if the type "is IEnumerable"? I could be way off here but I
thought most if not all array types were implicitly IEnumerable.

Chris.
Jun 27 '08 #6
Well, Array is abstract, so you will never actually have an Array
instance - just things that subclass it. But if you really must cater
for both T[] and Array, then perhaps just:

bool isArray = type.IsArray || type == typeof(Array);

Marc
Jun 27 '08 #7
Chris Shepherd wrote:
Norbert Pürringer wrote:
>Hello again,

I've got a type variable, e.g.

Type type;

Now I want to know whether the type represents an Array type
(System.Array).

type.IsArray results false because System.Array is an object, not an
array.

How can I find out, whether the type variable represents
System.Array?

Could to not see if the type "is IEnumerable"? I could be way off
here but I thought most if not all array types were implicitly
IEnumerable.
Sure... but so are many things that aren't arrays.
>
Chris.

Jun 27 '08 #8
Ben Voigt [C++ MVP] wrote:
>>How can I find out, whether the type variable represents
System.Array?
Could to not see if the type "is IEnumerable"? I could be way off
here but I thought most if not all array types were implicitly
IEnumerable.

Sure... but so are many things that aren't arrays.
I should have been clearer -- I was mentioning arrays in the sense of the
logical construct vs the literal class Array.

The OP should probably clarify the exact use scenario he's looking for.

Chris.

Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Laphan | last post by:
Hi All I'm using .getRows() with a local var array instead of doing a recursive loop so that I'm being a good ASP newvbie and closing my object i/o's (the recordset in this case) as quick as...
33
by: Matt Kruse | last post by:
I'm seeking the most robust and backwards-compatible (ie, no instanceof) isArray function. Here's what I have: function defined(o) { return typeof(o)!="undefined"; } function isArray(o) {...
18
by: Aaron Gray | last post by:
I know this has probably been argued to death, but I am going to raise it fresh again, and basically lets have an unofficial 'isArray()' contest that we can hopefully put it to rest as best as we...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.