473,662 Members | 2,752 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().G etFields()) {
...
}

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 19795
Hi Achim,

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

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

foreach (FieldInfo info in obj.GetType().G etFields()) {
...
}

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
3219
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 'const int' to 'char' I've tryed to define the size of it (char a ) but I get same warnings every time. What's wrong with this?
4
1998
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 only know the dimension on the end of reading, so I keep the array elements in an
1
1781
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 the syntax right. I thought I was able to go ArrayList.ToArray(typeof(UltraNode)) and be done with it. I then decided to just iterate through the ArrayList and build an array but I am having trouble there too.
1
2334
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. I've tried this as a public, global variable, and a local Dim - - that's all I really need in this case.
7
1497
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 defined below: Public Class Variable Inherits MarshalByRefObject '<remarks/> Public strVariableName As String
5
1776
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 (toolbar click event). 1) Dim f As Object 2) Select Case Trim$(ActiveMdiChild.Text) 3) f = CType(ActiveMdiChild, <Hard Coded Valid Form Object Based On Case>) 4) f.<Public Method> Now, I know that I could use an inherited form, but for a number...
0
3462
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 in vb.net I get a casting error when I execute the swap of : array(0)=array(10) array(10)=array(100) array(100)=array(0) The user defined type as 7 elements that are a mixtue of string and nemeric Thanks in advance for any help offered
2
10456
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 (property.PropertyType.IsArray) { object propertyValue =
4
3359
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: " SQL0008N The token "; char d; ..... ..... .... } v_abc; EXEC SQL END DECLARE SECTION
1
2420
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
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5655
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
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
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.