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

How can i display array element in C#?

I want to display array element in c#..how can i do that..can i use Console.WriteLine method directly to display??
For e.g.,
int[,]mArrayy=new int [2,4]{
{2,2,2,2},
{3,3,3,3}
};
Now how can i display those array elements??
Thank you..
Jul 18 '14 #1

✓ answered by horace1

try
Expand|Select|Wrap|Line Numbers
  1.             for (int x = 0; x < mArrayy.GetLength(0); x += 1)
  2.             {
  3.                 for (int y = 0; y < mArrayy.GetLength(1); y += 1)
  4.                 {
  5.                     Console.Write(mArrayy[x, y]);
  6.                 }
  7.                 Console.WriteLine();
  8.             }
  9.  

5 1403
horace1
1,510 Expert 1GB
e.g.
Expand|Select|Wrap|Line Numbers
  1.             Console.WriteLine("{0}", mArrayy[0, 0]);
  2.             Console.WriteLine("{0}", mArrayy[1, 2]);
Jul 18 '14 #2
Thnx 4 your ans..but how can i display them collectively..it will be a lengthy process...by writing over and over again..don't u think??
Thank you....
Jul 18 '14 #3
can i use foreach loop for this purpose?
Jul 18 '14 #4
horace1
1,510 Expert 1GB
try
Expand|Select|Wrap|Line Numbers
  1.             for (int x = 0; x < mArrayy.GetLength(0); x += 1)
  2.             {
  3.                 for (int y = 0; y < mArrayy.GetLength(1); y += 1)
  4.                 {
  5.                     Console.Write(mArrayy[x, y]);
  6.                 }
  7.                 Console.WriteLine();
  8.             }
  9.  
Jul 18 '14 #5
Thank You Sir...plz help me in future...I m a student..so i have lots of queries like these..:)
Jul 21 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: richbl | last post by:
Hello all, I have a question about unserializing a single array element from a serialized array. Can this be done, or must I first unserialize the array, and then access the element? For...
2
by: csx | last post by:
Hi all, Here's a simple problem I'm having problems with. How do I pass an array element to a function. For instance, values = new values(1, 1,'A',0); values = new values(2, 2,'B',1);...
26
by: Peter Olcott | last post by:
// // Is there something wrong with my syntax for the // Copy Constructor of an Array Element, or does // the C++ language not support this? // #include <stdio.h> #include <stdlib.h> ...
3
by: Kaz Kylheku | last post by:
Given some class C with array T x, is it possible to get a pointer-to-data-member to one of the elements? &C::x gives us a pointer-to-member-array: T (C::*). But I just want to get a T C::*...
4
by: garak | last post by:
Hi, I got the following problem : I have an defined an Array of different Actions: public PRootActions AllActions = new PRootActions ; I got a dynamic method where all Actions or other...
5
by: jtougas | last post by:
What is the way to the type of an array's elements? Array a = new long { 1, 2, 3 }; Type t = a.GetType(); Console.WriteLine( t.FullName ); This will write "System.Int64", but is not what I'm...
2
by: gregory_may | last post by:
Is there a way in VB.Net to declare a local variable that will manipulate an array element .... kind of like an item pointer to a global array?
7
by: Michael Bray | last post by:
Let's say I am using reflection to analyze my classes, and I have an array of another class. How do I get the base class that forms the array from a type? public class A { } A MyArray =...
2
by: getteddy | last post by:
hi i am working on array , i am facing a problem in comparing data base element with array element if not (objrs("namephase")=("despArray(ctr,0)+despArray(ctr,3)")) then or If...
5
by: dmorand | last post by:
I'm trying to validate whether or not an array element has been created. Here is what one of the arrays could look like: commentid = undefined commentid = undefined commentid = 1 commentid =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.