PC Review


Reply
Thread Tools Rate Thread

Arrays/Literal Notation

 
 
=?Utf-8?B?QUEyZTcyRQ==?=
Guest
Posts: n/a
 
      21st Feb 2007
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.
 
Reply With Quote
 
 
 
 
Barry Kelly
Guest
Posts: n/a
 
      21st Feb 2007
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/
 
Reply With Quote
 
Oliver Sturm
Guest
Posts: n/a
 
      21st Feb 2007
Hello AA2e72E,

Homework?


Oliver Sturm
--
http://www.sturmnet.org/blog
 
Reply With Quote
 
=?Utf-8?B?QUEyZTcyRQ==?=
Guest
Posts: n/a
 
      21st Feb 2007
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/
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st Feb 2007
AA2e72E <(E-Mail Removed)> wrote:
> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Peter Bradley
Guest
Posts: n/a
 
      21st Feb 2007
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" <(E-Mail Removed)> wrote in message
news:83F12FCB-887C-490E-B1DA-(E-Mail Removed)...
> 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/
>>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      21st Feb 2007
> 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" <(E-Mail Removed)> wrote in message
news:25635EEA-D0F4-49D0-B414-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
=?Utf-8?B?QUEyZTcyRQ==?=
Guest
Posts: n/a
 
      21st Feb 2007
Peter, thanks for another <almost> useless 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?



 
Reply With Quote
 
=?Utf-8?B?QUEyZTcyRQ==?=
Guest
Posts: n/a
 
      21st Feb 2007
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 ...
 
Reply With Quote
 
Mythran
Guest
Posts: n/a
 
      21st Feb 2007


"AA2e72E" <(E-Mail Removed)> wrote in message
news:25635EEA-D0F4-49D0-B414-(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array/Literal notation AA2e72E Microsoft Excel Programming 1 3rd Jun 2009 10:00 AM
Hungarian Notation Vs Pascal Notation? Grey Squirrel Microsoft Dot NET Framework 17 22nd Mar 2007 08:14 PM
Hungarian Notation Vs. Pascal Notation? Grey Squirrel Microsoft ASP .NET 6 21st Mar 2007 09:42 AM
Hungarian Notation Vs. Pascal Notation Grey Squirrel Microsoft Dot NET 3 19th Mar 2007 02:43 PM
Referencing Literal Arrays Vic Sowers Microsoft Excel Worksheet Functions 2 24th May 2005 12:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:57 AM.