473,386 Members | 1,630 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.

convert a jagged array into a multidimensional array

TS
is there some code somewhere that does this?

i have a jagged array that is not jagged, it has an equal number of rows and
columns in each array so it should convert but want to get the code to do it
somewhere.

thanks
Jan 21 '07 #1
5 10314
TS
example

say i have a jagged array with 2 array items and each array item has 2 value
items.

I want to turn that into an array[2,2], how do i do that?

thanks

"TS" <ma**********@nospam.nospamwrote in message
news:OH**************@TK2MSFTNGP02.phx.gbl...
is there some code somewhere that does this?

i have a jagged array that is not jagged, it has an equal number of rows
and columns in each array so it should convert but want to get the code to
do it somewhere.

thanks

Jan 21 '07 #2
TS <ma**********@nospam.nospamwrote:
example

say i have a jagged array with 2 array items and each array item has 2 value
items.

I want to turn that into an array[2,2], how do i do that?
I don't think there's any built-in way to do it. It wouldn't be too
hard to write a method to do it though.

--
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
Jan 21 '07 #3
Hi TS,

I am sorry to say that I don't think there's a direct way to convert a
jagged array into a multidimensional array. We need to loop through the
jagged array and assign each value to the multidimensional array.

The following is a sample.

int[] a0 = new int[2];
a0[0] = 1;
a0[1] = 2;

int[] a1 = new int[2];
a1[0] = 3;
a1[1] = 4;

int[][] a = new int[2][];
a[0] = a0;
a[1] = a1;

int[,] b = new int[2, 2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
b[i, j] = a[i][j];
}
}
Hope this helps.
If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 22 '07 #4
TS
thanks all who posted, i got a good method created.

"Linda Liu [MSFT]" <v-****@online.microsoft.comwrote in message
news:$S**************@TK2MSFTNGHUB02.phx.gbl...
Hi TS,

I am sorry to say that I don't think there's a direct way to convert a
jagged array into a multidimensional array. We need to loop through the
jagged array and assign each value to the multidimensional array.

The following is a sample.

int[] a0 = new int[2];
a0[0] = 1;
a0[1] = 2;

int[] a1 = new int[2];
a1[0] = 3;
a1[1] = 4;

int[][] a = new int[2][];
a[0] = a0;
a[1] = a1;

int[,] b = new int[2, 2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
b[i, j] = a[i][j];
}
}
Hope this helps.
If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 22 '07 #5
I'd like to propose that this be implemented internally as perhaps an
overloaded method or something in the framework. For instance, in Excel
interop and Excel services, the spreadsheet cells are returned as jagged
arrays which makes interpreting these values very *wordy. Jagged arrays need
to be more implementation friendly in my esteemed opinion :-)

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
"Linda Liu [MSFT]" <v-****@online.microsoft.comwrote in message
news:$S**************@TK2MSFTNGHUB02.phx.gbl...
Hi TS,

I am sorry to say that I don't think there's a direct way to convert a
jagged array into a multidimensional array. We need to loop through the
jagged array and assign each value to the multidimensional array.

The following is a sample.

int[] a0 = new int[2];
a0[0] = 1;
a0[1] = 2;

int[] a1 = new int[2];
a1[0] = 3;
a1[1] = 4;

int[][] a = new int[2][];
a[0] = a0;
a[1] = a1;

int[,] b = new int[2, 2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
b[i, j] = a[i][j];
}
}
Hope this helps.
If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 23 '07 #6

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

Similar topics

1
by: James dean | last post by:
I done a test and i really do not know the reason why a jagged array who has the same number of elements as a multidimensional array is faster here is my test. I assign a value and do a small...
3
by: James dean | last post by:
I have created algorithms in C# unsafe code and have fixed the arrays in memory for optimum performance. I use multidimensional arrays rather than jagged arrays. The algorithms i use usually read a...
3
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string...
1
by: xllx.relient.xllx | last post by:
Hi, I have two questions: 1.)Is it true that an rectangular array is really just an single dimensional array that lets itself be treated as a multi-dimensional array? For example the...
4
by: Alan Foxmore | last post by:
Hi everyone, I'm new to C# and I was hoping I could get some clarification on the syntax for jagged and multidimensional arrays. Here is my question: The following syntax is correct for...
2
by: Allen Maki | last post by:
Hi Everybody, I am new to VC.NET and I need your help. I would like the array to print characters as '.'s (dots) instead of 0s as in (see below in front of //------>>>>>. I tried to...
2
by: deko | last post by:
I trying to create a jagged array of two arrays, with the second array being an array of two-dimensional arrays. A graphical representation might look like this: x y y y x y x y y x ...
4
by: Sahar | last post by:
Hi there, I m trying to return an object (of my own written class) from a web service that contains jagged Arrays as public variables. Asp.Net is showing me the its serialized version on the...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.