473,506 Members | 17,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection: How to get the type of an array?

Hi,

I'm analyzing the fields of an object like this:

foreach (FieldInfo info in obj.GetType().GetFields()) {
...
}

Some of the fields are arrays, so I check for info.IsArray which works
fine and info.FieldType contains MyType[] for example. But how do I get
the base type of the array, i.e. MyType? Must be simple, but I could not
figure out how to do it!?

regards,
Achim
Feb 7 '07 #1
1 19779
Hi Achim,

You can use Type.GetElementType() to find out what type the array
contains. You might also need to check for Type.HasElementTypes first.
On Wed, 07 Feb 2007 11:46:30 +0100, Achim Domma <do***@procoders.net>
wrote:
Hi,

I'm analyzing the fields of an object like this:

foreach (FieldInfo info in obj.GetType().GetFields()) {
...
}

Some of the fields are arrays, so I check for info.IsArray which works
fine and info.FieldType contains MyType[] for example. But how do I get
the base type of the array, i.e. MyType? Must be simple, but I could not
figure out how to do it!?

regards,
Achim


--
Happy Coding!
Morten Wennevik [C# MVP]
Feb 7 '07 #2

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

Similar topics

2
3208
by: Sava Mikalački | last post by:
Hi there! My problem consists in this: When I define an array of char type like this: char a={'a','aa','aaa'}; I get a lot of warnings like warning C4305: 'initializing' : truncation from...
4
1995
by: Wernfried Schwenkner | last post by:
I want to deserialize a file. In one ofe my classes I have an array like: public class MyClass { public MyArray theArray; } i.e. an arry of an own defined class. While reading the file I...
1
1777
by: Jack Addington | last post by:
I have a method that takes an array of nodes (UltraNode) as a parameter. I've got an arrayList of objects that I am trying to convert to UltraNodes and pass to the method but I cannot seem to get...
1
2326
by: Elmo Watson | last post by:
My code : Line 71: Dim sFiles As String Line 72: Dim myFileArray As Array It breaks on Line 72 - - error message: Compiler Error Message: BC30002: Type 'Array' is not defined. ...
7
1490
by: William Apple | last post by:
Despite the fact this deals with webservices I believe it is a VB question. I am working on a test application that passes data to a webservice. The webservices takes a variable type that is...
5
1762
by: EdB | last post by:
I have an MDI form with similar child edit forms. The child Edit forms have public methods that of consistent names. I have a tool bar that calls these methods. Here's how I'm doing it now...
0
3455
by: Lex Harrelson | last post by:
I have user defined type dim 1000 deep....This data is collected from a comma delimited file....I want to sort the array with a method that requires the swapping of the compared type....tryng this...
2
10405
by: Velislav | last post by:
Hi, I've got the following piece of code: string GetPropertyValue(object jobCard, string propertyName, int index) { PropertyInfo property = jobCard.GetType().GetProperty(propertyName); if...
4
3355
by: nibakshi | last post by:
As i have defined a structure in EXEC SQL BEGIN and END section and i am declaring a structure type array variable after structure definition,but during precompilation it is throwing an error: "...
1
2415
by: Ahmad Nawaz | last post by:
I have a dropdown list which have some elements. I want to get all the elements of the dropdown list into a variable of type array. Any Idea???
0
7220
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
7105
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
7308
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,...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
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...
0
5617
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
3188
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...
0
1534
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 ...
0
410
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...

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.