【问题标题】:How to define array in asp.net nested array?如何在 asp.net 嵌套数组中定义数组?
【发布时间】:2017-03-21 13:08:54
【问题描述】:

在php中使用

$_array=array(
             1=>array("id"=>1,"name"=>"abc"),
             2=>array("id"=>2,"name"=>"vbn")

);
echo $_array[1]["id"];

asp.net c#如何使用?

【问题讨论】:

  • 抱歉,SO 不是代码转换工具。请添加您的 c# 代码并描述您遇到的问题
  • ASP.NET 没有数组。这是一个网络框架。 C# 可以,您需要做的就是指定尺寸。如果你不得不问如何定义一个数组,你可能应该在寻找 C# 教程。
  • 顺便说一句,您发布的内容更像是一个 object 数组,而不是嵌套数组。 PHP 有对象,那么为什么要使用数组呢?您应该创建一个具有 ID 和 Name 属性的类并定义一个 MyClass[] 数组或 List<MyClass> 列表。
  • 这是 php,不是 c#

标签: c# asp.net arrays


【解决方案1】:

在 c# 中你应该这样做:

class Program
{
    static void Main(string[] args)
    {
        Person p1 = new Person(1, "abc");
        Person p2 = new Person(2, "vbn");
        List<Person> list = new List<Person>();
        list.Add(p1);
        list.Add(p2);
    }

    public class Person
    {
        public Person(int id, string name)
        {
            this.id = id;
            this.name = name;
        }

        public int id { get; set; }
        public string name { get; set; }
    }

}

【讨论】:

    猜你喜欢
    • 2014-01-17
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 2021-11-30
    • 2021-11-15
    • 2019-04-09
    相关资源
    最近更新 更多