如何创建一个二维动态数组的长度? [英] How can I create a 2 dimensional dynamic length array?

查看:160
本文介绍了如何创建一个二维动态数组的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个2维数组,不知道第一个维度的大小。

I want to create a 2-dimensional array, without knowing the size of the first dimension.

例如我有一个未知的行数,当我创建一个数组。
每一行再present帐户。
4号出口列的每一行:ID,姓名,用户名,密码

For example I have an unknown number of rows, when I create an array. Every row represent an account. Exit 4 columns for every row: ID,name,user,password

我试着用锯齿状数组,但它是不可能有:

I tried with jagged array but it is not possible to have:

int[][] jaggedArray = new int[][3];

我也看了的ArrayList ,实施与clases和一些关于泛型。

Also I looked for ArrayList, implementation with clases and a little about Generics.

我在寻找一个解决方案,可以允许数据的易操控为:

I'm searching for a solution that can permit easy manipulation of data as:


  • 添加到列表中选择,输入元素

  • 使用数据库查询元素

  • 使用在其他功能的参数

由于我在.NET(C#)是新手,请给我提供code解决方案,而不是一般的(寻找)解决方案

Because I'm a newbie in .NET (C#) please provide me with code solutions, instead of generic(look for) solutions

推荐答案

IMO,自列是固定的,声明一个类为:

IMO, since the "columns" are fixed, declare a class for that:

public class Account
{
    public int ID {get;set;}
    public string Name {get;set;}
    public string User {get;set;}
    public string Password {get;set;} // you meant salted hash, right? ;p
}

现在有一个:

List<Account> list = new List<Account>();

这有你需要的一切:

添加到列表中选择,输入元素

add to list,select,input elements

list.Add

使用数据库查询的元素
  使用在其他功能的参数

using elements in database queries using as parameters in other functions

没有更多的信息模糊,但你可以通过任帐户或invidual值,或者整个列表。

vague without more info, but you can pass either the Account or invidual values, or the entire list.

这篇关于如何创建一个二维动态数组的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆