Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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 May 28th, 2004, 06:58 AM
Authorized User
 
Join Date: Mar 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Indexers with c#

hello
i want to create bool array and call each element in the array by kind of string, its mean that my array look like this:
arr["a"] = true;
arr["b"] = false;
arr["c"] =true;
and etc.

how can i do this? whether its possible?
thanks koby


 
Old May 28th, 2004, 07:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, you can do that. You need to create a HashTable instead of a bool Array:
Code:
Hashtable myBools = new Hashtable(3);
myBools.Add("a", true);
myBools.Add("b", false);
myBools.Add("c", true);

MessageBox.Show("Item C is " + myBools["c"]);
Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 28th, 2004, 09:52 AM
Authorized User
 
Join Date: Mar 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much
koby






Similar Threads
Thread Thread Starter Forum Replies Last Post
why use base[] indexers?? oooshola BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 31st, 2007 12:50 AM
Indexers and Properties pagates C# 5 March 15th, 2005 08:08 AM





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