Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > BOOK: Beginning Object-Oriented Programming with C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 29th, 2013, 09:31 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
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)
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06: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



All times are GMT -4. The time now is 02:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.