Wrox Programmer Forums
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 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 October 28th, 2011, 10:09 AM
Authorized User
 
Join Date: Sep 2011
Posts: 24
Thanks: 7
Thanked 0 Times in 0 Posts
Default Collections

In Chapter 11 example Program 1
In program.cs
We are creating an instance of Cow class and assigned it to
an array of type Animal.
but in next line without creating an instance of Chicken class
we are assigning it to the array
Code:
animalArray[1]=new Chicken("Ken");
here what's the name of the instance of Chicken Class i.e object name


When calling myAnimal.Name
Code:
 Console.WriteLine("New {0} object added to Array collections,Name={1}",myAnimal.ToString(),myAnimal.Name);
what happens to the code.Please
split and explain the execution cycle
 
Old October 29th, 2011, 03:38 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by arun_babu_a View Post
but in next line without creating an instance of Chicken class
we are assigning it to the array
Code:
animalArray[1]=new Chicken("Ken");
No, an instance of the Chicken class is created. It's just not assigned to a variable but instead directly to the second element of the array.

This code creates a new instance:
Code:
new Chicken("Ken")
And here the instance is assigned to the second element of the array:
Code:
animalArray[1] = new Chicken("Ken")
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
 
Old October 29th, 2011, 04:02 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

And the second question,
Quote:
Originally Posted by arun_babu_a View Post
When calling myAnimal.Name
Code:
 Console.WriteLine("New {0} object added to Array collections,Name={1}",myAnimal.ToString(),myAnimal.Name);
what happens to the code.Please
split and explain the execution cycle
With
Code:
myAnimal.Name
you are accessing the get accessor of the Name property that returns the value of the name variable of the object. The Name property is defined on page 279
Code:
protected string name;
public string Name
{
  get
  {
    return name;
  }
  set
  {
    name = value;
  }
}
Properties are defined starting on page 244, "Defining Properties".
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel





Similar Threads
Thread Thread Starter Forum Replies Last Post
collections help bennyt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 July 26th, 2008 01:30 AM
Collections and Recordsets MLC1985 Beginning VB 6 10 August 1st, 2007 09:13 AM
Collections in C#? shenku C# 1 August 17th, 2005 06:16 AM
Collections question GregV VB.NET 2002/2003 Basics 0 August 6th, 2003 12:24 PM





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