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

You are currently viewing the BOOK: Beginning Visual C# 2005 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 May 3rd, 2007, 05:57 PM
Authorized User
 
Join Date: Apr 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Larryz
Default

Thats an excellent explanation..... thanks.. no one else responds to my questions they must be lame lol..... i mean not they my questions must be....

i have kinda worked out what colllections are, but finding indexers hard..and the concept in general, i get its a collection of objects etc.....


eg public mycollection this[int mycollectindex]
// what is the this refering to...
{
get
{
return (mycollection) List[mycollectindex];
}
// here i guess it returns mycollection with the index value mycollectindex ?

set
{
List[mycollectindex] = value;
// what is this returning
}

in this code....
from the book ...... page 282
Animals is a collection...
Animals animalCollection = new Animals();
animalCollection.Add(new cow("jack"));
animal is an object allowing cow to be derived from it
what confuses me is the call to Add which an Animal object..
i am assuming the obect is first create via the code...new cow("jack") which it will look at the Animal object to see what to do.... and then that object jack is added to the collection... otherwise it wont know what object jack is in order to add it......?

}

 
Old May 3rd, 2007, 11:06 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In so far as people in here being Lame, that isn't the case. There are alot of skilled contribtors here (Imar, Peter, Joe, Happy, etc) and if I wasn't answering your questions, I am sure one of them would be! ;]

Anyway, about collections.

I don't have the book that you are referencing so what I am going to do is explain this using an array list and the DataTable object.

ArrayList arr = new ArrayList();
arr.Add(new DataTable("foo"));

Now, depending on what I am doing and what the use of this particular collection is I can do something like:

foreach(DataTable t in arr)
{
//do something with each object in the collection
}

Your get statement is returning the object at the given index your set statement doesn't return anything, it sets the specified index with the supplied value.

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 4th, 2007, 06:38 AM
Authorized User
 
Join Date: Apr 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Larryz
Default

thats great but i dont have a clue of what a DataTable is....

i am , the newbie here...

Anyway i have worked out basicly a collection in terms of the book is a collection of obejects... which different from an array of objects..

eg Animal[] animalArray = new Animal[2];

Its uses and arraylist..
ArrayList AnimalArrayList = new ArrayList();
this ArrayList together with CollectionBase allows collections to be created ....

But i am not sure of all that... a cleaner explanation than the book would, be Very helpfull.....

thanks in advance ..Larry .

 
Old May 4th, 2007, 09:07 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmm. You have lost me.

An arraylist implements these interfaces: ICollections, IEnumerable, IList, and ICloneable

This is what gives it the ability to create a Collection of objects; for example: when you call Arraylist.Add[value] the Add property is defined in the IList interface and then implemented inside of the System.Collections.ArrayList class to provide this functionality.

I am sorry but i am not sure if i have answered your question. =
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 6th, 2007, 12:59 PM
Authorized User
 
Join Date: Apr 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Larryz
Default

OK a slight change in topic

Ordinary properties and indexers i am kind of stuck by syytax
and understanding how they work....

An ordinary property, maybe defined as follows.


public int myProperty

get
{
 return myInt;
}
set
{
myInt = value;
}

In the above example, we may call it
via
myobject.myProperty = 6;

hence using the set branch to set the value..

we use the name myProperty to set that property and we can see
from the property signature that it will set an integer value.

public int myProperty

i hope i am making sense ....

But take this example...

public Animal this[int animalIndex]
// This is a special property called and indexer..
// it is used in object collections
get
{
 return (Animal) List[animalIndex];
}
set
{
  List[animalIndex] = value;
}

The confusing bit for me..... is

A) The signature of the property

Ordinary properties and indexers i am kind of stuck by syytax
and understanding how they work....

An ordinary property, maybe defined as follows.



public int myProperty
//its public it sets an integer type the name is myProperty.
// we explictly call it.. to use it.

get
{
 return myInt;
}
set
{
myInt = value;
}

In the above example, we may call it
via
myobject.myProperty = 6;

hence using the set branch to set the value..

we use the name myProperty to set that property and we can see
from the property signature that it will set an integer value.

public int myProperty

i hope i am making sense ....

But take this example...

public Animal this[int animalIndex]

Animal is s class so its not the name
and its not called directly as in the above example
how does the compiler know that
when for example
            animalsCollection[2] = new chicken("franky")
to use this indexer...
In the normal property we call it via its name....

and point B
I dont get the property signature of the indexer

public Animal this[int animalIndex]
What are all these bits ...What is Animal what is this[in animalIndex]

i cant break down the signature as i did for ordinary properties.

There isnt a name for the property as such in the signature.

All i can think of is the object name is the name and it takes and index.
and it sets an object type of Animal.


 
Old May 7th, 2007, 08:09 AM
Authorized User
 
Join Date: Apr 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Larryz
Default


Posted - 05/06/2007 : 11:42:54 PM Show Profile Email Poster Edit Topic Send Larryz an AOL message Reply with Quote Delete Topic
public void CopyTo(Cards targetCards)
      {
         for (int index = 0; index < this.Count; index++)
         {
            targetCards[index] = this[index];
         }
      }

The code above is called via objectName.CopyTo(cards)
cards is an collection....

what is the this refering to... is it... objectName.count, where objecctName is a collection.

thanks Larry..






Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 3.5 answers in Professional ASP.NET 3.5 jminatel ASP.NET 3.5 Professionals 1 August 22nd, 2011 07:34 AM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
Database diagram in .net using asp.net,c#.net scotttiger ADO.NET 2 February 16th, 2005 01:35 AM





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