Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2007, 05:40 AM
Registered User
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic declaration of an array

How to declare an array dynamically to: 1. an int type 2. a string type 3. a float type

T R Balakrishnan
 
Old September 4th, 2007, 09:36 AM
Registered User
 
Join Date: Aug 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi tenkasian,

I'm not sure I understood your question, but maybe the following code helps you:
I.
            int nCount = 3;
            int[] aIntegerNumbers = new int[nCount];
            aIntegerNumbers[0] = 20;
            aIntegerNumbers[1] = 10;
            aIntegerNumbers[2] = 30;

II.
            List<int> lstIntegerNumbers = new List<int>();

            lstIntegerNumbers.Add(20);
            lstIntegerNumbers.Add(10);
            lstIntegerNumbers.Add(30);

If this doesn't help you, please provide more information about what you need.
 
Old September 5th, 2007, 10:14 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you mean a single array with multiple types in it then you should declare the array as the Object type:

object[] aryThings = new object[count];

Of course, then you will need to know exactly what type is in which element.

Explain to us what you want to do in more detail, there may be a better way.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic picturebox array thomaz C# 3 September 17th, 2008 01:15 PM
Dynamic array of struct bobwrx C# 2 September 14th, 2006 06:12 AM
Dynamic array - please help OC Beginning VB 6 5 March 21st, 2004 05:11 AM
Dynamic Control array [email protected] Visual C++ 6 September 3rd, 2003 08:48 AM
String array declaration mkpriya VS.NET 2002/2003 8 June 13th, 2003 07:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.