473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

arrays and parse enumerators

I have

.....

enum day {monday, tuesday, wednesday};

myArray[2,2]=5;

i=(int)Enum.Parse(typeof(day), wednesday);

Console.Writeline(i);

Console.Writeline(myArray[2,2]);
outputs:

2
5

as expected. If i try

Console.Writeline(myArray[i,i]);
i get index outside bound of array error. Any ideas anyone?
Nov 15 '05 #1
5 1467
Had to correct a couple of syntax errors, this compiles and works;

Other than some "" missing in the Enum.Parse call and Console.WriteLine not
having a capital "L", I couldn't see any errors.

Josh
Microsoft.com Tools

//
public class Tester
{
enum day {monday, tuesday, wednesday};
[STAThread]
static void Main(string[] args)
{

int[,] myArray = new int[3,3];

myArray[2,2]=5;

int i=(int)Enum.Parse(typeof(day), "wednesday");

Console.WriteLine(i);

Console.WriteLine(myArray[2,2]);

Console.WriteLine(myArray[i,i]);

}
}
//
"tony collier" <me*****@hotmail.com> wrote in message
news:Xn*******************************@140.99.99.1 30...
I have

....

enum day {monday, tuesday, wednesday};

myArray[2,2]=5;

i=(int)Enum.Parse(typeof(day), wednesday);

Console.Writeline(i);

Console.Writeline(myArray[2,2]);
outputs:

2
5

as expected. If i try

Console.Writeline(myArray[i,i]);
i get index outside bound of array error. Any ideas anyone?

Nov 15 '05 #2
tony collier <me*****@hotmail.com> wrote:
I have

....

enum day {monday, tuesday, wednesday};

myArray[2,2]=5;

i=(int)Enum.Parse(typeof(day), wednesday);

Console.Writeline(i);
Console.Writeline(myArray[2,2]);

outputs:

2
5

as expected. If i try

Console.Writeline(myArray[i,i]);

i get index outside bound of array error. Any ideas anyone?


Could you show a short but complete program which demonstrates the
problem?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in
news:MP************************@msnews.microsoft.c om:
tony collier <me*****@hotmail.com> wrote:
I have

....

enum day {monday, tuesday, wednesday};

myArray[2,2]=5;

i=(int)Enum.Parse(typeof(day), wednesday);

Console.Writeline(i);
Console.Writeline(myArray[2,2]);

outputs:

2
5

as expected. If i try

Console.Writeline(myArray[i,i]);

i get index outside bound of array error. Any ideas anyone?


Could you show a short but complete program which demonstrates the
problem?

asp.net based project>>>
in global.asax :>

......
void Session_Start(Object Sender, EventArgs e)
{

string [,] pricetable=new string [5,12];

Session["pricetable"]=pricetable;
}

............

in page_load
enum bookstores

{
Amazon,
Blackwells,
CoopBookshop,
CountryBookshop,
HistoryBookshopcom,
StudentBookWorldcom,
Swotbooks,
TescoBookStore,
TheBookPlace,
WHSmithOnline,
WHSmithOnlineSD,
ComputerManuals,
ComputerBooks
};

StringBuilder RawHtml=new StringBuilder();

RawHtml.Append( load of screenscraped data );

StringBuilder Bookstore=new StringBuilder();

string [,] pricetable= (string[,])Session["pricetable"];

string price="";

int storeno;

//grab bookstore data between > and < html tags that will correspond
to one of the enum bookstore elements

startindex=RawHtml.ToString().IndexOf(">",startind ex)+1;

endindex=RawHtml.ToString).IndexOf"<",startindex);

Bookstore.Append(RawHtml.ToString().Substring(star tindex, endindex-
startindex));
// set storeno equal to integer corresponding to bookstore element

storeno=(int)Enum.Parse(typeof(bookstores),Booksto re.ToString());
/* cut out more data from RawHtml and store in pricetable array which is
indexed with a direct correlation between stores and their enumerated
values*/
startindex=RawHtml.ToString().IndexOf("egen>",star tindex)+5;

endindex=RawHtml.ToString().IndexOf("<",startindex );

price=RawHtml.ToString().Substring(startindex, endindex-startindex);

pricetable[storeno]=price;

and this is where i get the error. if i do a response.write for storeno
it returns an integer correlating to enum bookstore values and if i do a
response.write for pricetable[0 upto 10 or whatever] this works fine
also.
Nov 15 '05 #4
tony collier <me*****@hotmail.com> wrote:
<snip>
asp.net based project>>>


It's hard to get all that going - please convert it to a simple console
app which basically does nothing apart from showing the bug.

However, I do note that you've got new string[5,12] despite the fact
that there are 13 stores. Also, I'm not convinced that

pricetable[storeno]=price;

is going to work when pricetable is a 2D array...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in
news:MP************************@msnews.microsoft.c om:
tony collier <me*****@hotmail.com> wrote:
<snip>
asp.net based project>>>


It's hard to get all that going - please convert it to a simple console
app which basically does nothing apart from showing the bug.

However, I do note that you've got new string[5,12] despite the fact
that there are 13 stores. Also, I'm not convinced that

pricetable[storeno]=price;

is going to work when pricetable is a 2D array...


spot on jon. The whole thing was wrapped in a loop which gave me the
second index for pricetable which i omitted from the example and as you
correctly identified the problem was a really dumb one where i should have
set the pricetable array to [5,13].

I can't stress how impressed i am with all your help. thankyou very much.
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Kim Jensen | last post by:
Hi there I currently have a .txt file (lets call it jimharper.txt) that holds a number of arrays like for instance: $name = "Jim Harper" $relatives = "Joan Harper (wife)" $relatives =...
35
by: Troll | last post by:
Hi, I need to write a script which reads some data and reports the findings. Just to give you an idea the structure is similar to the following. Data input example: HEADING 1 **********...
6
by: Matt Taylor | last post by:
I'm trying to write an x86 assembler in C++ for use in a debugger. What I'd like do is to use template specialization to prevent invalid combinations from compiling. Thus one could not accidentally...
6
by: Tim Davis | last post by:
I am currently writing a class which I would like to make "enumerable" by inheriting from IEnumerable. The documentation says that the IEnumerator.MoveNext method should throw an exception if the...
0
by: jg | last post by:
just for those who have to deal with legacy application that supports COM, OCX, and WINAPI(_stadcall) - c-style?, I worked out the COM interface for function out array parameters. For example...
0
by: Frank | last post by:
Hi, I use rpy on linux to call R functions. Works fine up to the following problem: How to parse arrays (no vectors, that means 2-dimensional) to R without much effort? The following code...
1
muaddubby
by: muaddubby | last post by:
Hello all and happy new year. I've seen several posts floating around asking about string enumerators in C#, and generally speaking, they're not supported. I've come up with a way around it...
1
nitindel
by: nitindel | last post by:
Hi All, May i have an in depth article of enumerators in C#..that explains the Enumerators in C# very precisely.... Thanks, Nitin
3
by: erbrose | last post by:
Hello all! Newbie here, I've been tasked with a fairly intensive project here and my perl skills are still at a minimum so this post may eventually turn into a long one, but I am only going to ask...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.