#region 数据和变量的定义
private int i_count; //模块中的数据长度
private int [] iChannelA; //通道A中的数据数组
private int [] iChannelB; //通道B中的数据数组
private int [] iChannelC; //通道C中的数据数组
private int [] iChannelD; //通道D中的数据数组
private DateTime dt_insertTime; //插入数据时间
#endregion #region 初始化类
/// <summary>
/// 连接硬件初始化数据
/// </summary>
public FlowData()
{
i_count=UseDsadDll.DsadSetBlockMode(1);
this.dt_insertTime=DateTime.Now;
iChannelA=new int[this.i_count];
iChannelB=new int[this.i_count];
iChannelC=new int[this.i_count];
iChannelD=new int[this.i_count];
for(int i=0;i<this.i_count;i++)
{
iChannelA[i]=UseDsadDll.DsadInputA();
iChannelB[i]=UseDsadDll.DsadInputB();
iChannelC[i]=UseDsadDll.DsadInputC();
iChannelD[i]=UseDsadDll.DsadInputCount();
}
UseDsadDll.DsadSetBlockMode(0);
}
/// <summary>
/// 复制初始化数据
/// </summary>
/// <param name="copyFrom"></param>
public FlowData(FlowData copyFrom)
{
this.i_count=copyFrom.Count;
this.iChannelA=copyFrom.ChannelA;
this.iChannelB=copyFrom.ChannelB;
this.iChannelC=copyFrom.ChannelC;
this.iChannelD=copyFrom.ChannelD;
this.dt_insertTime=copyFrom.InsertTime;
} /// <summary>
/// 自定义数据
/// </summary>
/// <param name="length">存储各通道长度</param>
/// <param name="channelA">通道A数组</param>
/// <param name="channelB">通道B数组</param>
/// <param name="channelC">通道C数组</param>
/// <param name="channelD">通道D数组</param>
/// <param name="dt">时间</param>
public FlowData(int length,int[] channelA,int[] channelB,int [] channelC,int [] channelD,DateTime dt)
{
this.i_count=length;
this.dt_insertTime=dt; this.iChannelA=new int[length];
this.iChannelB=new int[length];
this.iChannelC=new int[length];
this.iChannelD=new int[length]; this.iChannelA=channelA;
this.iChannelB=channelB;
this.iChannelC=channelC;
this.iChannelD=channelD;
}
#endregion /// <summary>
/// 获取模块中的数据长度
/// </summary>
public int Count
{
get
{
return this.i_count;
}
}
/// <summary>
/// 获取通道A中的数据
/// </summary>
public int[] ChannelA
{
get
{
return this.iChannelA;
}
}
/// <summary>
/// 获取通道B中的数据
/// </summary>
public int[] ChannelB
{
get
{
return this.iChannelB;
}
}
/// <summary>
/// 获取通道C中的数据
/// </summary>
public int [] ChannelC
{
get
{
return this.iChannelC;
}
}
/// <summary>
/// 获取通道D中的数据
/// </summary>
public int[] ChannelD
{
get
{
return this.iChannelD;
}
} /// <summary>
/// 获取读取模块的时间
/// </summary>
public DateTime InsertTime
{
get
{
return this.dt_insertTime;
}
}
}
注:连接硬件的构造函数,是连接某个硬件填充数据
解决方案 »
- 大神们,帮我看看图片在数据库存储读取问题。
- .txt和.jpg等格式附件不能打开
- 关于RFID卡的问题
- 从“纸牌问题”到“火柴问题”的困惑
- 如何把 winform 中的 tabPage 的标签的背景颜色改掉
- VS.NET(C#.net 或 VB.net)下开发的ACCESS数据库程序,能否让多用户或多个应用程序同时访问(读写操作)一个ACCESS数据库?
- 竟请关注!三层软件系统即将发布!
- C# 用HttpWebRequest模拟一个虚假的IP或在post时可以即时更改ip包 ??
- 求救帖 vs.net安装后的问题!
- 最后10分:如何让一个FORM程序运行后不出现在进程列表里面?
- 各位牛人,求救啊!! 调用 vc的dll结构体指针?????
- c# 中如何只存储dateTimePicker的日期
public FlowData(int length,int[] channelA,int[] channelB,int [] channelC,int [] channelD,DateTime dt)
{
//
// parameter checking goes here
//
if( channelA == null || channelA.Length != length ) throw new ArgumentException("......");
this.i_count=length;
this.dt_insertTime=dt; this.iChannelA=new int[length]; // useless, delete these lines
this.iChannelB=new int[length]; // .
this.iChannelC=new int[length]; // .
this.iChannelD=new int[length]; // . this.iChannelA=channelA;
this.iChannelB=channelB;
this.iChannelC=channelC;
this.iChannelD=channelD;
}
public FlowData(int length,int[] channelA,int[] channelB,int [] channelC,int [] channelD,DateTime dt)
{
this.i_count=length;
this.dt_insertTime=dt; this.iChannelA=new int[length];
this.iChannelB=new int[length];
this.iChannelC=new int[length];
this.iChannelD=new int[length]; this.iChannelA=channelA;
this.iChannelB=channelB;
this.iChannelC=channelC;
this.iChannelD=channelD;
}其中 this.iChannelA=new int[length];
this.iChannelB=new int[length];
this.iChannelC=new int[length];
this.iChannelD=new int[length];
是没必要的,删去这四句,直接用随后四句的赋值就可以了。
我更愿意像下面这么做public class A
{
ilist<B> res;
pulic void ilist<B> getDate()
{
return res;
}
}public class B
{
}
现在你复制后的数据,如果源对象改变,那么你这个新对象同时也会改变。
看看下面代码执行后会怎样:FlowData a = new FlowData();
a.ChannelA[0] = 99;// b 复制 a 的数据
FlowData b = new FlowData(a);// 设置 a 的数据看看
a.ChannelA[0] = 88;// 断言 a.ChannelA[0] 和 b.ChannelA[0]是相等的
Debug.Assert(a.ChannelA[0] == b.ChannelA[0]);// 如果要做到A 和 B 复制后的数据分离,你需要这样子
this.iChannelA = new int[length];
this.iChannelB = new int[length];
this.iChannelC = new int[length];
this.iChannelD = new int[length];channelA.CopyTo(this.iChannelA, 0);
channelB.CopyTo(this.iChannelB, 0);
channelC.CopyTo(this.iChannelC, 0);
channelD.CopyTo(this.iChannelD, 0);