English 中文(简体)
界定两个方面 动态轨道
原标题:Defining two dimensional Dynamic Array

How can I define two dimensional dynamic array? If I want to use List<>, can I use it for two dimensions?

最佳回答

我知道,不存在两维阵列的内在动态等同,但你可以轻松地获得同样功能。

1. 界定与本《行动计划》一致的类别:

public class Coordinate : IEquatable<Coordinate>
{
     public Coordinate(int x, int y);
     public int X { get; }
     public int Y { get; }
     // override Equals and GetHashcode...
}

现在,你可以创立一系列这样的协调事例。

如果你创立了,你将保证,如果由于平等地位高于平等地位,你不能再增加一ordinate。

如果你想要的话,你可以把坐标扩大到<代码>。 Co coordinated<T> as this:

public class Coordinate<T> //...
{
    // previous stuff...

    public T Item { get; set; }
}

这将使你能够把一个严格类型的项目与每个协调结合起来,例如:

var items = new HashSet<Coordinate<string>>();
items.Add(new Coordinate<string>(1, 4) { Item = "Foo" });
items.Add(new Coordinate<string>(7, 19) { Item = "Foo" });
// ...
问题回答

这将是这样的:

List<List<string>> twoDimensional = new List<List<string>>();

但我认为,利用名单来做到这一点是不现实的,更好地利用阵列......

您可使用清单,例如: 清单和编号非常快。

但是,通过两阵列,你们需要:

int[,] arr = new int[100,100];

这应当比清单更快。

http://msdn.microsoft.com/en-us/library/a288453%28VS.71%29.aspx” rel=“nofollow noreferer” 此处的任何途径是:type[,] name for multi ranges,type [] 标签阵列名称(改动<代码> 类型,用于储存阵列的物体类型)。

你们的阵列永远不会有活力。

各位都可以通过名单(除非你通过提供额外索引来看待某个问题),除非你简单地寻找名单(这不是多维)。

这将是(图示清单):

List<List<string>>
Dictionary<T, List<T>>

例如,如果T是“扼制”的话,你可以这样使用:

var pathes = new Dictionary<string, List<string>>();

pathes.Add("X", new List<string>());
pathes["X"].Add("a");
pathes["X"].Add("b");
pathes["X"].Add("c");

pathes.Add("Y", new List<string>());
pathes["Y"].Add("b");
pathes["Y"].Add("z");




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签