using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleAppSet { class Class1 { private void StorePerson() { List<Person> list = new List<Person>(); Person p1 = new Person(); p1.FIRST_NAME = "Tom"; p1.LAST_NAME = "Li"; p1.AGE = 24; list.Add(p1); } } struct Person { public string FIRST_NAME; public string LAST_NAME; public int AGE; } }
哦,错了。 这样: List <List<int>> x = new List <List<int>>() {new List<int> { 1, 3, 5, 7 }, new List<int>{ 6, 1, 4, 4 }, new List<int>{ 7, 0, 2, 3 } };
List<List<int>> x=new List<List<int>> ();那么,如何将下列二维数据赋值给x呢:1 3 5 7
6 1 4 4
7 0 2 3
List<List<int>> x = new List<List<int>> ({ { 1, 3, 5, 7 }, { 6, 1, 4, 4 }, { 7, 0, 2, 3 } });
这样语法错误,应该怎么初始化呢?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleAppSet
{
class Class1
{
private void StorePerson()
{
List<Person> list = new List<Person>();
Person p1 = new Person();
p1.FIRST_NAME = "Tom";
p1.LAST_NAME = "Li";
p1.AGE = 24; list.Add(p1);
}
} struct Person
{
public string FIRST_NAME;
public string LAST_NAME;
public int AGE;
}
}
这样:
List <List<int>> x = new List <List<int>>() {new List<int> { 1, 3, 5, 7 }, new List<int>{ 6, 1, 4, 4 }, new List<int>{ 7, 0, 2, 3 } };