473,554 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Arr ay" is not really good, isn't it?

Norbert
Jun 27 '08 #1
8 6433
"Norbert Pürringer" <th*******@graf fiti.netwrote:
The way type.Name == "System.Arr ay" is not really good, isn't it?
typeof(Array).I sAssignableFrom (type)

Eq.
Jun 27 '08 #2
On Apr 28, 12:07 pm, Norbert Pürringer <thalio...@graf fiti.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.co mwrote:
What exactly do you mean by that? type.IsArray should be fine.
typeof(anything[]).IsArray is true, but typeof(Array).I sArray is false.

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

typeof(anything[]).IsArray is true, but typeof(Array).I sArray 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.Arra y?
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
3502
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 possible. My problem is that I can't seem to use this to complete good effect because the IsArray statement doesn't seem to work with a local var...
33
10502
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) { // If these conditions aren't met, it certainly isn't an Array
18
1825
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 can. I have found things that work perfectly well as long as you don't try them on MSIE, ie adding Object and Array prototype isArray functions,...
0
7584
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7783
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7879
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6129
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1117
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
828
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.