SortedList, Why Parenthesis instead of Brackets? 
Author Message
 SortedList, Why Parenthesis instead of Brackets?

I was looking at the SortedList and it uses Parenthesis () instead of [] in
order to use its Indexer.

Arrays and ArrayList use the [].

Just wondering why this is?

Thanks.



Sat, 15 May 2004 07:58:13 GMT  
 SortedList, Why Parenthesis instead of Brackets?
Are you sure? I don't have access to the docs right now but brackets are
part of C#.

--

Sincerely,

Josh Mitts
Microsoft .NET MVP (.NET Framework, C#, .NET CF/SDE)

http://www.joshmitts.com


Quote:
> I was looking at the SortedList and it uses Parenthesis () instead of []
in
> order to use its Indexer.

> Arrays and ArrayList use the [].

> Just wondering why this is?

> Thanks.



Sat, 15 May 2004 08:31:01 GMT  
 SortedList, Why Parenthesis instead of Brackets?
You should have been more selective in your cross-post list. For VB
programmers, that is not a concern. We always uses parens for arguments, it
does not matter if it is a method, property, or indexer.

--
Jonathan Allen


Quote:
> I was looking at the SortedList and it uses Parenthesis () instead of []
in
> order to use its Indexer.

> Arrays and ArrayList use the [].

> Just wondering why this is?

> Thanks.



Sat, 15 May 2004 08:25:19 GMT  
 SortedList, Why Parenthesis instead of Brackets?
public class SortedList : IDictionary, ICollection, IEnumerable, ICloneable

I'm not sure what you're referring to in this posting, because SortedList
does indeed use []'s... however, SortedList actually contains 2 arrays, one
with keys and one with values (as ICollection objects).

Using the SortedList[key] (see listing for 'Item' in class descriptions)
returns the value.
There are 4 interesting methods:

GetKey(int index) will also return the key at the index given.
GetByIndex(int index) will return the value at the index given.
*** GetValue is, unfortunately, used in IDictionary.  It would have been a
nicely symmetric method name here. ***

GetKeyList() returns an IList interface, which gives access to the Keys,
using []
GetValueList() returns and IList interface, which gives access to the
Values, using []

IndexOfKey(object key) and IndexOfValue(object value) round out the classes
ability to find each index, key, and value in the list.

Thus, this is a more complex class that Array or ArrayList, yet tends to be
easy to use.


Quote:
> I was looking at the SortedList and it uses Parenthesis () instead of []
in
> order to use its Indexer.

> Arrays and ArrayList use the [].

> Just wondering why this is?

> Thanks.



Sat, 15 May 2004 09:19:26 GMT  
 SortedList, Why Parenthesis instead of Brackets?
I was using the methods, GetKey() and GetByIndex().

I guess I was confused by the documentation when using the Index to get the
key and the value.

and not realizing the SortedList[key] gives you the value

Also thinking that GetKey() should be GetKey[], but I guess it's a method
so.....

Thanks.


Quote:
> public class SortedList : IDictionary, ICollection, IEnumerable,
ICloneable

> I'm not sure what you're referring to in this posting, because SortedList
> does indeed use []'s... however, SortedList actually contains 2 arrays,
one
> with keys and one with values (as ICollection objects).

> Using the SortedList[key] (see listing for 'Item' in class descriptions)
> returns the value.
> There are 4 interesting methods:

> GetKey(int index) will also return the key at the index given.
> GetByIndex(int index) will return the value at the index given.
> *** GetValue is, unfortunately, used in IDictionary.  It would have been a
> nicely symmetric method name here. ***

> GetKeyList() returns an IList interface, which gives access to the Keys,
> using []
> GetValueList() returns and IList interface, which gives access to the
> Values, using []

> IndexOfKey(object key) and IndexOfValue(object value) round out the
classes
> ability to find each index, key, and value in the list.

> Thus, this is a more complex class that Array or ArrayList, yet tends to
be
> easy to use.



> > I was looking at the SortedList and it uses Parenthesis () instead of []
> in
> > order to use its Indexer.

> > Arrays and ArrayList use the [].

> > Just wondering why this is?

> > Thanks.



Sat, 15 May 2004 14:11:10 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. about calling methord with parentheses or without parentheses

2. Help! Why RTF instead of Plain Text

3. why javascript instead of vbscript?

4. ~Why should one use VB instead of DELHPI?

5. Why to use a TextBox instead of a RichTextBox

6. Why a picturebox instead of form

7. ~Why should one use VB instead of DELHPI?

8. Why Windows help file instead of HTTP?

9. Why Use dbList instead of msFlexGrid?

10. Newbie: Why use Access instead of VB to create front end

11. why why why why

12. Why why why why?

 

 
Powered by phpBB® Forum Software