Solved

How can I declare dynamic  two dimensional Array in Csharp?

Posted on 2016-08-17
4
36 Views
Last Modified: 2016-09-05
How can I define two dimensional dynamic array? ,i'm Writing Dijkstra Algorithm program,i wanna each node that connected to another nodes  its value save into array.in fact , it should be dynamic two dimensional Array.not specified which one of nodes connected to another nodes.picture
0
Comment
Question by:Member_2_7970207
  • 2
4 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 166 total points (awarded by participants)
Comment Utility
This isn't what you asked for but maybe a list of 2-tuples might be useful:
https://msdn.microsoft.com/en-us/library/dd268536(v=vs.110).aspx
0
 
LVL 32

Accepted Solution

by:
sarabande earned 167 total points (awarded by participants)
Comment Utility
if you know the dimensions bevor you do it by this (somehow weird) syntax:

int [, ] array2d = new int [4, 2];

Open in new window


if not you may use a List

List< List<Node> > array2d = new List< List<Node> > ;
array2d.Add(new List<Node>);

array2d[0].Add(new Node(7, 53));

Open in new window


(i hope the syntax is correct).

Sara
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 167 total points (awarded by participants)
Comment Utility
I don't think you'll want sarabande's array syntax. That defines a square array, which means both dimensions are fixed to what you declare them as. You probably want an array of arrays. It's somewhat related to a square array, but the only the first dimension is fixed--the 2nd dimension is dynamic:

int[][] array2d = new int[5][];

It's similar, in effect, to the list of lists that sarabande purposes.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
Closed with an equal share of points.

Sara
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now