C#数据结构Struct
简单来讲,结构就是一堆数据的集合。
定义方式
public struct books
{
string title;
string author;
}
结构的使用
books book1;
book1.tilte = “C#自学”;
book1.author = “ft”;
结构中包含定义数组,可以用list来定义。
public struct books
{
public string title;
public string author;
public List aa;
}
books book1;
book1.aa = new List();
数据结构中包含定义数组,数组中包含数据结构,数组中定义数据结构,需要先申明一个数据结构
public struct books
{
public List <book_content> aa;
}
struct book_content
{
public string a;
public int b;
public string c;
}
books book1
book_content book_content1
下面的可以放循环里操作,这样得到的结构,就可以转成XML或者json,和前端JS交换数据
book_content1.a = “1”;
book_content1.b = 9;
book_content1.c = “3”
book1.aa.add(book_content1)