Wrox Programmer Forums
|
BOOK: Beginning Object-Oriented Programming with C#
This is the forum to discuss the Wrox book Beginning Object-Oriented Programming with C# by Jack Purdum; ISBN: 978-1-1183-3692-2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Object-Oriented Programming with 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 January 29th, 2013, 10:31 AM
Friend of Wrox
 
Join Date: Sep 2008
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Dynamic arrays of object members

A reader wrote to me and asked how to create an array of object members, but where the size of the array is known only at runtime. In other words, the size of the array is not know until after the user is running the program.

For example, suppose you have a class named clsData and within that class is a property named distributionList. Because you know you eventually want an array of this property, somewhere in scope you would write:

clsData.distributionList[] myList;

Note that you have declared a variable named myList, you have not defined it. This means that the rvalue of myList is null because no memory has actually been allocated for the array. All you have is variable named myList that is capable of pointing to an array of distributionList members.

Now, sometime later after you have determined the number of elements you need in the array (e.g., size), you can write:

myList = new clsData.distributionList[size];

This statement is a data definition because Windows now goes out and grabs enough memory to hold size elements of a distributionList member.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic arrays[First] sasoo7 Java Basics 0 April 18th, 2012 05:39 PM
handling event for a dynamic object deepak_8282 General .NET 2 May 14th, 2007 12:42 PM
dynamic variable/object names TheBFJ Excel VBA 2 November 13th, 2006 07:11 AM
Try-Catch Method for Dynamic Arrays DuncanM Visual C++ 1 September 14th, 2006 12:11 PM
Dynamic object instantiation trisonics C# 2 July 28th, 2005 11:20 PM





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