我写个简单的吧.实现你要的效果,但不是结构数组 只给你个思路,你可以运行一下试试using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { List<ClsArr> list = new List<ClsArr>(); list.Add(new ClsArr(1, "a1", "b1")); list.Add(new ClsArr(2, "a2", "b2")); list.Add(new ClsArr(3, "a3", "b3")); this.dataGridView1.DataSource = list; } } public class ClsArr { private int a; private string b; private string c; public ClsArr(int _a,string _b,string _c) { a = _a; b = _b; c = _c; } public int A { get { return a; } } public string B { get { return b; } } public string C { get { return c; } } } }
3. CZ6125 H TU21OCT DLCPEK HK2 0800 0910 E --T2 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace flights_cs { public partial class Form1 : Form { struct hbxinxi { public string strFlyno; public string strFlymes; public string strFlydate; public string strCity; public string strYuding; public string strLeave; public string strArriave; } public Form1() { InitializeComponent(); } private void richTextBox1_TextChanged(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void button1_Click_1(object sender, EventArgs e) { hbxinxi hbxx; hbxx = new hbxinxi(); string myString = " 3. CZ6125 H TU21OCT DLCPEK HK2 0800 0910 E --T2!" ; string a = myString.Substring(5, 6); string b = myString.Substring(12, 1); string c = myString.Substring(16, 7); string d = myString.Substring(25, 6); string eE = myString.Substring(32, 3); string f = myString.Substring(38, 4); string g = myString.Substring(43, 4); hbxx.strFlyno = a; hbxx.strFlymes = b; hbxx.strFlydate = c; hbxx.strCity = d; hbxx.strYuding = eE; hbxx.strLeave = f; hbxx.strArriave = g; richTextBox1.Text = "航班号:" + hbxx.strFlyno + "\n" + "舱位信息:" + hbxx.strFlymes + "\n" + "起飞日期:" + hbxx.strFlydate + "\n" + "城市段:" + hbxx.strCity + "\n" + "预定状态:" + hbxx.strYuding + "\n" + "起飞时间:" + hbxx.strLeave + "\n" + "到达时间:" + hbxx.strArriave; } 这是我之前做的,但不是数组,现在问题是数组解析的是2条数据,我搞不懂了啊,书也翻了就是不开窍啊,希望高手指点1,2
struct Flight { public string No; public string Status; public string DepartureDate; public string Cities; public string PreStatus; public string DepartureTime; public string ArrivalTime; } Flight[] filgt = new Flight[2]; filgt[0] = new Flight(); filgt[0].No = "CZ6125"; filgt[0].Status = "H"; //.....................
public struct TestStruct { private string _a; private string _b; public string A { get { return _a; } set { _a = value; } } public string B { get { return _b; } set { _b = value; } } public TestStruct(string a, string b) { _a = a; _b = b; } } public class TestClass { private TestStruct[] _structs; public TestClass() { _structs = new TestStruct[2]; _structs[0] = new TestStruct( "11", "22"); _structs[1] = new TestStruct( "33", "44"); } public TestStruct[] Structs { get { return (TestStruct[])_structs.Clone(); } } }
只给你个思路,你可以运行一下试试using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
List<ClsArr> list = new List<ClsArr>();
list.Add(new ClsArr(1, "a1", "b1"));
list.Add(new ClsArr(2, "a2", "b2"));
list.Add(new ClsArr(3, "a3", "b3"));
this.dataGridView1.DataSource = list;
}
} public class ClsArr
{
private int a;
private string b;
private string c; public ClsArr(int _a,string _b,string _c)
{
a = _a;
b = _b;
c = _c;
} public int A
{
get
{
return a;
}
} public string B
{
get
{
return b;
}
} public string C
{
get
{
return c;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace flights_cs
{
public partial class Form1 : Form
{
struct hbxinxi
{
public string strFlyno;
public string strFlymes;
public string strFlydate;
public string strCity;
public string strYuding;
public string strLeave;
public string strArriave; }
public Form1()
{
InitializeComponent();
} private void richTextBox1_TextChanged(object sender, EventArgs e)
{ } private void label1_Click(object sender, EventArgs e)
{ } private void button1_Click_1(object sender, EventArgs e)
{
hbxinxi hbxx; hbxx = new hbxinxi();
string myString = " 3. CZ6125 H TU21OCT DLCPEK HK2 0800 0910 E --T2!" ;
string a = myString.Substring(5, 6);
string b = myString.Substring(12, 1);
string c = myString.Substring(16, 7);
string d = myString.Substring(25, 6);
string eE = myString.Substring(32, 3);
string f = myString.Substring(38, 4);
string g = myString.Substring(43, 4);
hbxx.strFlyno = a;
hbxx.strFlymes = b;
hbxx.strFlydate = c;
hbxx.strCity = d;
hbxx.strYuding = eE;
hbxx.strLeave = f;
hbxx.strArriave = g; richTextBox1.Text = "航班号:" + hbxx.strFlyno + "\n" + "舱位信息:"
+ hbxx.strFlymes + "\n" + "起飞日期:" + hbxx.strFlydate + "\n" + "城市段:"
+ hbxx.strCity + "\n" + "预定状态:" + hbxx.strYuding + "\n" + "起飞时间:"
+ hbxx.strLeave + "\n" + "到达时间:" + hbxx.strArriave; }
这是我之前做的,但不是数组,现在问题是数组解析的是2条数据,我搞不懂了啊,书也翻了就是不开窍啊,希望高手指点1,2
struct Flight
{
public string No;
public string Status;
public string DepartureDate;
public string Cities;
public string PreStatus;
public string DepartureTime;
public string ArrivalTime;
} Flight[] filgt = new Flight[2];
filgt[0] = new Flight();
filgt[0].No = "CZ6125";
filgt[0].Status = "H";
//.....................
public struct TestStruct
{
private string _a;
private string _b; public string A
{
get { return _a; }
set { _a = value; }
} public string B
{
get { return _b; }
set { _b = value; }
} public TestStruct(string a, string b)
{
_a = a;
_b = b;
}
} public class TestClass
{
private TestStruct[] _structs; public TestClass()
{
_structs = new TestStruct[2];
_structs[0] = new TestStruct(
"11",
"22");
_structs[1] = new TestStruct(
"33",
"44");
} public TestStruct[] Structs
{
get
{
return (TestStruct[])_structs.Clone();
}
}
}
这个意思吧?