473,322 Members | 1,307 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,322 software developers and data experts.

Creating typed arrays using reflection

Hi,

I'd like to create typed arrays during runtime, sort of
like this:

Array vals = Array.CreateInstance(objType, noElements);

The problem is that objType will not be a "base" type
like Double or Int32, but rather an array type, like
Double[] or Int32[]. Is there any way of creating, say,
an array of doubles from the double[] system type?
Nov 15 '05 #1
2 12488
Ranier Dunno <eb*****@hotmail.com> wrote:
I'd like to create typed arrays during runtime, sort of
like this:

Array vals = Array.CreateInstance(objType, noElements);

The problem is that objType will not be a "base" type
like Double or Int32, but rather an array type, like
Double[] or Int32[]. Is there any way of creating, say,
an array of doubles from the double[] system type?


Yup - you just need to get the element type, which you can do with
Type.GetElementType. In other words:

Array vals = Array.CreateInstance (objType.GetElementType(),
noElements);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
-----Original Message-----
Ranier Dunno <eb*****@hotmail.com> wrote:
I'd like to create typed arrays during runtime, sort of like this:

Array vals = Array.CreateInstance(objType, noElements);

The problem is that objType will not be a "base" type
like Double or Int32, but rather an array type, like
Double[] or Int32[]. Is there any way of creating, say, an array of doubles from the double[] system type?
Yup - you just need to get the element type, which you

can do withType.GetElementType. In other words:

Array vals = Array.CreateInstance (objType.GetElementType (), noElements);


Ah, so there was a method - thanks :-)
Nov 15 '05 #3

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

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
0
by: Jeremy Summers | last post by:
Has anyone run into problems creating typed datasets from complex schemas? I am attempting to create a Typed Dataset in Visual Studio .Net from a .xsd schema file for a industry standard web...
11
by: Boni | last post by:
Dear all, currently I only found a possibility to create for each type it's own typed array. I am sick to create for each of my types a separate array class. In C++ there are so called templates:...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
4
by: Søren M. Olesen | last post by:
Hi Is it (any way) possible using reflection to set an indicator (property, variable, attribute,..). on an object before it actually instantiated, so that this indicator can be used in the...
8
by: Ympostor | last post by:
Why can't I do this (it gives a syntactic error):? foreach (System.Reflection.PropertyInfo oProp in oObject.GetType().GetProperties()) { if ((oProp.PropertyType.IsGenericType) &&...
4
by: =?Utf-8?B?QWJoaQ==?= | last post by:
I am using Reflection to invoke methods dynamically. I have got a special requirement where I need to pass a value to method by setting the custom method attribute. As I cannot change the...
4
by: Gugale at Lincoln | last post by:
Hi, I am using reflection to read names from enum and creating radio buttons inside a groupbox. Everything is working fine. However, I am not able to adjust the size of the group box to fit the...
10
Plater
by: Plater | last post by:
I'm a bit boggled by this since I am rather new to using reflection. I want to attach an event handler via Reflection (which I can do), but I want to NOT have to know the exact event delegate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.