473,320 Members | 1,920 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,320 software developers and data experts.

Arrays/Literal Notation

int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0, 7, 8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to create
the array?

The rank of the array is 3, its dimensions are 3,1,4.

How would I change the code to produce

a. an array of dimension 3,2,4?
b. an array of rank 4?

Thanks.
Feb 21 '07 #1
22 4004
AA2e72E wrote:
int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0, 7, 8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to create
the array?

The rank of the array is 3, its dimensions are 3,1,4.
Hint: count '3' '1' '4'. It's equal to 3.

Another hint:
* What is there 4 of in the top example?
* Given that you've gotten what there's 4 of, what is there only one of,
for its given level of nesting?
* Can you spot what there's 3 of now?
How would I change the code to produce

a. an array of dimension 3,2,4?
b. an array of rank 4?
Do you own homework - it's not hard!

-- Barry

--
http://barrkel.blogspot.com/
Feb 21 '07 #2
Hello AA2e72E,

Homework?
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 21 '07 #3
Learn to read before jumping to prescribe.

My note says that I know the rank (number of dimensions) is 3; I go on to
tell you that the dimensions are 3,1,4. The question was how would I modify
the right hand side (RHS) such that the rank stayed as 3 but he dimensions
were 3,2,4 i.e how would I increase the second dimension to 1.

The second question was whether the RHS was a 'literal ' notation.

If you did not know, or cannot be bothered to understand what is written,
why do't you simply choose not to respond? Your answer adds nothing.

PS: I had bothered to research my own answers but came with nothing; hence
the post.
"Barry Kelly" wrote:
AA2e72E wrote:
int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0, 7, 8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to create
the array?

The rank of the array is 3, its dimensions are 3,1,4.

Hint: count '3' '1' '4'. It's equal to 3.

Another hint:
* What is there 4 of in the top example?
* Given that you've gotten what there's 4 of, what is there only one of,
for its given level of nesting?
* Can you spot what there's 3 of now?
How would I change the code to produce

a. an array of dimension 3,2,4?
b. an array of rank 4?

Do you own homework - it's not hard!

-- Barry

--
http://barrkel.blogspot.com/
Feb 21 '07 #4
AA2e72E <AA*****@discussions.microsoft.comwrote:
Learn to read before jumping to prescribe.

My note says that I know the rank (number of dimensions) is 3; I go on to
tell you that the dimensions are 3,1,4. The question was how would I modify
the right hand side (RHS) such that the rank stayed as 3 but he dimensions
were 3,2,4 i.e how would I increase the second dimension to 1.

The second question was whether the RHS was a 'literal ' notation.

If you did not know, or cannot be bothered to understand what is written,
why do't you simply choose not to respond? Your answer adds nothing.
Barry gave a very good answer, which led you through how to understand
the different dimensions.

I suggest you reread his answer, and work through it slowly - by the
end, you'll be able to understand how to answer the questions yourself.

What I would suggest is that you put each bracing level on a new line,
rather than the whole thing in one line. That might make it clearer.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 21 '07 #5
Well, that's a pretty good way of ensuring that no-one will help you with
your homework. Congratulations. I hope the foot gets better soon.

Just for your info, in case you should ever post to a newsgroup again
seeking help with homework, you should ensure that you do the following:

* State clearly that you are looking for help with homework
* Explain what research you have carried out, what you have already tried
and what the results were.
* Assure the group that answers will be credited to the group or individual
giving the advice and that you will not try to pass off other people's work
as your own.

That's what I did when studying for my MSc recently. I got lots of help and
I was as good as my word in terms of crediting other people when they had
helped me out. I even posted my answers so that people could check it out
for themselves. This also got me a commendation from my tutor.

Oh! and finally. Remember that students can be dismissed for plagiarism,
and that professors also read newsgroups.

Peter
"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
Learn to read before jumping to prescribe.

My note says that I know the rank (number of dimensions) is 3; I go on to
tell you that the dimensions are 3,1,4. The question was how would I
modify
the right hand side (RHS) such that the rank stayed as 3 but he dimensions
were 3,2,4 i.e how would I increase the second dimension to 1.

The second question was whether the RHS was a 'literal ' notation.

If you did not know, or cannot be bothered to understand what is written,
why do't you simply choose not to respond? Your answer adds nothing.

PS: I had bothered to research my own answers but came with nothing; hence
the post.
"Barry Kelly" wrote:
>AA2e72E wrote:
int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0,
7, 8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to
create
the array?

The rank of the array is 3, its dimensions are 3,1,4.

Hint: count '3' '1' '4'. It's equal to 3.

Another hint:
* What is there 4 of in the top example?
* Given that you've gotten what there's 4 of, what is there only one of,
for its given level of nesting?
* Can you spot what there's 3 of now?
How would I change the code to produce

a. an array of dimension 3,2,4?
b. an array of rank 4?

Do you own homework - it's not hard!

-- Barry

--
http://barrkel.blogspot.com/

Feb 21 '07 #6
int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0, 7,
8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to create
the array?

The rank of the array is 3, its dimensions are 3,1,4.
Since you already know what dimension and rank the first array declaration
is, it would be elementary for you to produce another according to the
specifications you've given, unless a teacher had given you this as a
problem, and you were simply trying to get someone to solve it for you. But
if that were the case, I would not be doing you any favor to solve it for
you, since programming is all problem-solving, and to solve your problem for
you would not give you any experience in problem-solving.

However, I will give you a link to a C# ECMA specification that you should
be able to use to figure it out for yourself:

http://www.jaggersoft.com/csharp_standard/toc.htm

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.
"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0, 7,
8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to create
the array?

The rank of the array is 3, its dimensions are 3,1,4.

How would I change the code to produce

a. an array of dimension 3,2,4?
b. an array of rank 4?

Thanks.

Feb 21 '07 #7
Peter, thanks for another <almostuseless answer; however, I now understand
the implication of 'homework' : I originally understood it to me 'do your own
research'

Let me assure you, this has nothing to do with homework; I am in my 50's
moving on from VB into C#. So far so good, but I do get stuck sometimes, as
in this situation.

I looked for the answers in "C# Language Reference" and did not find it;
search with Google and was not successful there either.

If you create a new project and put a button on it, and have this code in
its click event:

int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1,
0, 7, 8 } } }; // 3D
string xx="";
for (int i=0;i<array.Rank;i++)
{
xx += " " + (array.GetUpperBound(i)+1).ToString();
}
MessageBox.Show(xx);

You will have an insight and how I got the dimensions. I know that I need to
specify the elements of the next second dimension within the braces of the
RHS; tied several things and no success!

So, could someone just answer the questions, please?

Feb 21 '07 #8
Kevin, thanks; I try and find the answer using your link. I am sure it will
be there.

As you will see from a previous reply, I am not trying to get someone else
to solve it for me (I am not a student); in fact, for the context that I am
working on, I simply needed to establish that the array was square but got
side-tracked ( .. for something I need to do later).
I agree, that the best way to learn is to solve the problems oneself;
however, after a while, there is a tradeoff between simply asking and
persevering ...
Feb 21 '07 #9


"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
int[, ,] array = { { { 1, 2, 3, 3 }}, { { 7, -1, 9, 0 } }, { { -1, 0, 7,
8 }
} }; // 3D

In the line of code above, am I using 'literal' syntax/notation to create
the array?

The rank of the array is 3, its dimensions are 3,1,4.

How would I change the code to produce

a. an array of dimension 3,2,4?
b. an array of rank 4?

Thanks.
When dealing with multi-dimensional arrays, it may be helpful to re-organize
the code of the array literals to help identify the different "layers" of
the array, such as:

int[, ,] array =
{
{
{ 1, 2, 3, 3 }
},
{
{ 7, -1, 9, 0 }
},
{
{ -1, 0, 7, 8 }
}
}; // 3D

Does this help you identify what your looking for? I didn't give it away,
but am trying to help you see what you need and come to the conclusion(s)
yourself. Try playing with it a bit...

HTH,
Mythran
Feb 21 '07 #10
Thanks, Mythran. I'll get there, looks like later rather than sooner!

I know that line breaks mean nothing in C# except when dealing with verbatim
strings and that splitting my expression as you suggest might help me think
this through.

I do not recall seeing any sample/example code in any book or on MSDN that
splits the expression for arrays over several lines. I wonder why?

My first language is APL; in case you do not know anything about it, it
excels at array handling ( for instance, the inverse of a square matrix is
returned in one line!).

Still, need to acquire new skills .....
Thanks everyone.
Feb 21 '07 #11
Figured out answers to my questions relating to dimension and rank; however,
whether or not my expression is using 'literal' notation, I don't know. The
espression 'literal notation' is used in JavaScript documentation when
arrays are created by an expression ([ instead of { in JavaScript) rather
than dimensioned and have each element populated via a loop. I'll assume this
carries through to C#.
Feb 21 '07 #12

"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
Figured out answers to my questions relating to dimension and rank;
however,
whether or not my expression is using 'literal' notation, I don't know.
The
espression 'literal notation' is used in JavaScript documentation when
arrays are created by an expression ([ instead of { in JavaScript) rather
than dimensioned and have each element populated via a loop. I'll assume
this
carries through to C#.

It's array initialization syntax, it cannot be used under any conditions
except to initialize an array. Unlike a numeric or string literal which
actually is useable as a number or string, the braces syntax cannot be used
in place of an array, hence it is not an "array literal". There is an array
literal syntax which is somewhat different and can be used anywhere an array
can, but that is not it.
Feb 21 '07 #13
"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:eR**************@TK2MSFTNGP06.phx.gbl...
Well, that's a pretty good way of ensuring that no-one will help you with
your homework. Congratulations. I hope the foot gets better soon.
Despite his protestations, I agree with you, Peter. This looks exactly like
a homework question to teach C#, rather than having the slightest practical
value (which is why he hasn't specified any).

Just my opinion, but I'm sticking with it.

///ark
Feb 22 '07 #14
Not only another self appointed high priest of PATRONISATION, or warden of
student morality but also an AUTHORITY on C#: take your stance to its natural
conclusion and tell Microsoft that arrays are of no practical value and that
they should take it out of the language and its documentation forthwith.
Feb 22 '07 #15
AA2e72E <AA*****@discussions.microsoft.comwrote:
Thanks, Mythran. I'll get there, looks like later rather than sooner!

I know that line breaks mean nothing in C# except when dealing with verbatim
strings and that splitting my expression as you suggest might help me think
this through.

I do not recall seeing any sample/example code in any book or on MSDN that
splits the expression for arrays over several lines. I wonder why?
Because in real life code, 3-dimensional and 4-dimensional array
literals are pretty rare to start with.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 22 '07 #16
They probably are.

The background to what I was doing was to use APL via Interop; APL is strong
on arrays permiting arithmetic on then (irrespective of dimensions or rank)
almost as if they were scalars if they were conformable.

When I have done this using Excel, I found that while APL arrays are row
major, Excel arrays are column major. I needed to figure out whether there
was a similar issue with C# arrays. Hence the need to create C# arrays to
pass into APL and vice versa in order to test. Fortunately, C# arrays are row
major too.

I needed to get to this conclusion quickly without the hurdle of lectures
and prescriptions from some quarters; this was a big surprise to me as I
normally see this on Microsoft basher sites. I refer to the Excel newsgroup
quite a lot: it is an absolute model for newsgroup: an objective for this
newgroup?
Feb 23 '07 #17
AA2e72E <AA*****@discussions.microsoft.comwrote:

<snip>
I needed to get to this conclusion quickly without the hurdle of lectures
and prescriptions from some quarters; this was a big surprise to me as I
normally see this on Microsoft basher sites. I refer to the Excel newsgroup
quite a lot: it is an absolute model for newsgroup: an objective for this
newgroup?
You appeared to show no interest in learning how things worked, you
just snapped at someone who tried to help you. I bet that doesn't go
down well on the Excel newsgroup either.

Now, if you try to work *with* those who are trying to help you, you'll
find that there are lots of people who are prepared to put in a lot of
time helping you. Just remember that *they're* helping *you*, so you're
the one with something to lose from the conversation turning sour.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 24 '07 #18
you just snapped at someone who tried to help you.

I assume you are refering to Barry's reply; it was valuable until his
statement "Do you own homework - it's not hard!" Originally, I took that to
mean do your own research rather than his suspicion that I might be a student
trying to get the forum to solve my problem.

You also invite me to realise that 'they' are helping 'me': If I did not
know that, I would not have posted the question and I don't see how "Do you
own homework - it's not hard!" was helping me.

I do not think newsgroup respondents have any business being prescriptive;
they can
1. ignore a post,
2. or resolve it,
3. or show a better resolution of a solution provided by another respondent,
4. or refer them to a link that has the solution,
5. or simply hint at a solution.

It becomes very interesting and a valuable source of learning when scenario
3 comes into play.

As far as I can see, that is how the Excel newsgroup works (have a look at
he responses from Tom Ogilvy, also an MVP). And, as I see it, none of us
actually invent solutions, we simply adopt or adapt what is there; we are all
learning, even MVPs are in the same boat albeit further downstream. So there
is little justification for claiming the high moral ground faced with
'simple' or 'naive' questions.

Feb 25 '07 #19
AA2e72E <AA*****@discussions.microsoft.comwrote:
you just snapped at someone who tried to help you.

I assume you are refering to Barry's reply; it was valuable until his
statement "Do you own homework - it's not hard!"
And yet your reply included "Your answer adds nothing." Hardly a vote
of thanks, is it?
Originally, I took that to
mean do your own research rather than his suspicion that I might be a student
trying to get the forum to solve my problem.
No, it was saying: "I've given you all the tools you need to do your
homework, now come up with the answers yourselves."
You also invite me to realise that 'they' are helping 'me': If I did not
know that, I would not have posted the question and I don't see how "Do you
own homework - it's not hard!" was helping me.
You've already admitted that right until the last line, the response
was helpful.
I do not think newsgroup respondents have any business being prescriptive;
Have you noticed how you're being prescriptive yourself? You're trying
to tell the participants of this newsgroup how to behave. How is that
*not* prescriptive?
they can
1. ignore a post,
2. or resolve it,
3. or show a better resolution of a solution provided by another respondent,
4. or refer them to a link that has the solution,
5. or simply hint at a solution.
Similarly, you could have:
1) Ignored Barry's post
2) Acknowledged the value in it, but explained gently how it wasn't
homework in reply to the last line
3) Read the post carefully, several times, until you understood the
answer

Instead, your reply was basically rude.
It becomes very interesting and a valuable source of learning when scenario
3 comes into play.

As far as I can see, that is how the Excel newsgroup works (have a look at
he responses from Tom Ogilvy, also an MVP). And, as I see it, none of us
actually invent solutions, we simply adopt or adapt what is there; we are all
learning, even MVPs are in the same boat albeit further downstream. So there
is little justification for claiming the high moral ground faced with
'simple' or 'naive' questions.
Simple and naive questions are almost always answered kindly. Homework
questions (as yours *looked like*, even if it wasn't) are usually
answered in a way which would teach the student how to get the answer,
rather than by giving the answers themselves. From a few posts I've
just read on the Excel group (admittedly from 2004) it's an attitude
which is taken there as well.

No doubt it would have been better if Barry had put "We won't do your
homework, we'll just help you to do it yourself" instead of "Do you own
homework - it's not hard!" but I hardly think he deserved the reply you
gave. I suggest you reread that reply and consider how you might feel
if you'd received it from someone you'd been trying to help.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 25 '07 #20
Jon,
I was not being prescriptive but simply describing what I observe in other
Micorosft newsgroups, expecially the Excel one. I have obertved this high and
mighty put down attitude in non Microsoft sites ( e.g, say Oracle) and it can
a a big surprise here.

You are absolutely right, I could have simply ignored Barry's reply and the
one that followed it and waited ... for the one from Mythran.

Feb 25 '07 #21
AA2e72E wrote:
I could have simply ignored Barry's reply
Don't worry, I (and perhaps others) will be sure to ignore you too :)

-- Barry

--
http://barrkel.blogspot.com/
Feb 25 '07 #22
Barry, note that I said Barry's *reply*, not Barry to which your response is
'perhaps others will ignore *you* too'. Why so personal? Be that as it may.

I still don't think that the last sentence added anything to your reply and
it provoked my response, perhaps, I will concede, a little harsh and was
prompted by the other post that simply said 'Homework?' Water under the
bridge and all that!

If I am (or questions from me are ignored), what can I say? This kind of
concensus is unlikely (others did respond in this same thread) and of course
there are plenty of materials on the web and in print and other forums
(including another Microsoft C# forum) from which to glean answers. For what
it is worth, your response was timely and useful up to the last sentence and
the useful part was conveyed better (to me) by the post from Mythran.




Feb 25 '07 #23

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

Similar topics

7
by: Terence | last post by:
I usually program in Java, so I am a bit confused about usint pointers in C. I would really appreciate if someone can help me. Case 1: ====== // Is this function no good? Since str is a...
1
by: aliensite | last post by:
<html> <body> <script> // object constructor function names(fname,lname){ this.fname=fname; this.lname=lname } // object arrays list = new Array()
12
by: Duderonomoy | last post by:
Hello, I am querying the JavaScript community to learn if others are having problems with Safari and JavaScript arrays: myImages = ; then referenced like this:
34
by: Christopher Benson-Manica | last post by:
If an array is sparse, say something like var foo=; foo=4; foo='baz'; foo='moo'; is there a way to iterate through the entire array? --
4
by: meltedown | last post by:
Theres something very basic about javascript arrays I'm missing. The value of unit.value is 17.00 and value of the qty.value is 5 and I put these values into an array: myarray.value]=qty.value;...
6
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
20
by: mechanicfem | last post by:
I thought (as they're in c99) that flexible arrays were there for a number of reasons - but I also thought they'd be great for stepping into structures (say) that were aligned in memory after (say)...
9
by: mdh | last post by:
>From the list of questions...arrays certianly seem to be the biggest source of puzzlement. I can understand why. I reluctantly ask this...knowing it does not work, but the issue is why? ( It is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.