c#如何实现以下效果?

kongcheng32 2012-06-15 02:42:41

PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);

...全文
360 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
__天涯寻梦 2012-06-15
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 的回复:]
谢谢了,问题解决,真是高手,拜你为师,行吗?
[/Quote]
这就不用了,有问题在 CSDN 上提出,大家都会热心回答的
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
谢谢了,问题解决,真是高手,拜你为师,行吗?
__天涯寻梦 2012-06-15
  • 打赏
  • 举报
回复
for (int n = 0; n <= ICol; ICol++)
改成
for (int n = 0; n <= ICol; n++)
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复

if(ds1.Tables[0].Rows.Count>0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count;i++ )
{

PosGroup.LastUpdateTime = Convert.ToInt32(ds1.Tables[0].Rows[i]["UPD"]);
IRow = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Line"]) - 1;
ICol = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Col"]) - 1;
ILayer = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Layer"]) - 1;

var lane = PosGroup.Lane;
var row = lane.Row;

for (int m = 0; m <= IRow; m++)
{
PosGroup.Lane.Row[m] = new WMS_test.publicpra.TRow();
for (int n = 0; n <= ICol; ICol++)
{
PosGroup.Lane.Row[m].Col[n] = new WMS_test.publicpra.TCol();
for (int h = 0; h <= ILayer; h++)
{
PosGroup.Lane.Row[m].Col[n].Layer[h] = new WMS_test.publicpra.TLayer();
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.Zone_ID = Convert.ToInt32(ds1.Tables[0].Rows[i]["Zone_ID"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PID = Convert.ToInt32(ds1.Tables[0].Rows[i]["PID"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.HasSetValue = true;
}
}
}

kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
是不是出现死循环了
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
这次有数据了,但电脑卡住了
__天涯寻梦 2012-06-15
  • 打赏
  • 举报
回复
把 for(int m=0;m<=IRow;m++) 循环整个换成下面的代码,看哪行出的错
var lane = PosGroup.Lane;
var row = lane.Row;

for (int m = 0; m <= IRow; m++)
{
PosGroup.Lane.Row[m] = new TRow();
for (int n = 0; n <= ICol; ICol++)
{
PosGroup.Lane.Row[m].Col[n] = new TCol();
for (int h = 0; h <= ILayer; h++)
{
PosGroup.Lane.Row[m].Col[n].Layer[h] = new TLayer();
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.Zone_ID = Convert.ToInt32(ds1.Tables[0].Rows[i]["Zone_ID"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PID = Convert.ToInt32(ds1.Tables[0].Rows[i]["PID"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.HasSetValue = true;
}
}
}
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
已经加了,还是不行
__天涯寻梦 2012-06-15
  • 打赏
  • 举报
回复
PosGroup 声明的地方加上
TPosGroup PosGroup = new TPosGroup();
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
在PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
提示:未将对象引用设置到对象的实例
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复

if(ds1.Tables[0].Rows.Count>0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count;i++ )
{

PosGroup.LastUpdateTime = Convert.ToInt32(ds1.Tables[0].Rows[i]["UPD"]);
IRow = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Line"]) - 1;
ICol = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Col"]) - 1;
ILayer = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Layer"]) - 1;

//PosGroup.Lane = new publicpra.TLane();
//PosGroup.Lane.Row = new publicpra.TRow[2];
//PosGroup.Lane.Row[IRow].Col = new publicpra.TCol[14];
//PosGroup.Lane.Row[IRow].Col[ICol].Layer = new publicpra.TLayer[11];
//PosGroup.Lane.Row[IRow].Col[ICol].Layer[ILayer].Pos = new publicpra.TPos();


for(int m=0;m<=IRow;m++)
{
for (int n = 0; n <= ICol; ICol++)
{
for (int h = 0; h <= ILayer;h++ )
{
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.Zone_ID = Convert.ToInt32(ds1.Tables[0].Rows[i]["Zone_ID"]);

PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PID = Convert.ToInt32(ds1.Tables[0].Rows[i]["PID"]);

PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.HasSetValue = true;
}

}

}

}
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
不行呀,提示:未将对象引用设置到对象的实例
__天涯寻梦 2012-06-15
  • 打赏
  • 举报
回复
数组长度设定一个合适的值
public class TPosGroup
{
public TLane Lane = new TLane();
}

public class TLane
{
public TRow[] Row = new TRow[100];
}

public class TRow
{
public TCol[] Col = new TCol[100];
}

public class TCol
{
public TLayer[] Layer = new TLayer[100];
}

public class TLayer
{
public TPos Pos = new TPos();
}

public class TPos
{
public long PID;
public int PosState;
public int TypeOfState;
public int TypeOfCusID;
public int Zone_ID;
public bool HasSetValue;
}
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
怎么实例化呀?
金龙-Super 2012-06-15
  • 打赏
  • 举报
回复
支持8楼,你都是用c#了,还那么坚持结构体干啥?
__天涯寻梦 2012-06-15
  • 打赏
  • 举报
回复
把 struct 都换成 class ,使用时都 new 实例化
牛哥_ 2012-06-15
  • 打赏
  • 举报
回复
放到两类中 在2中 实例化1类 在调用1方法
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
谁帮我解决一下,想了一天了!
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复
我现在定义两个方法1,2,1方法是用来存放从数据库取出来的数据,2方法调用1方法,现在的问题是数据只是存在于方法1中,方法2调用方法1时无法将数据带到方法2中
kongcheng32 2012-06-15
  • 打赏
  • 举报
回复

public struct TPosGroup
{

public TLane Lane;

}

public struct TLane
{


public TRow[] Row;


}

public struct TRow
{
public TCol[] Col;


}

public struct TCol
{
public TLayer[] Layer;


}

public struct TLayer
{
public TPos Pos;


}

public struct TPos
{
public long PID;
public int PosState;
public int TypeOfState;
public int TypeOfCusID;
public int Zone_ID;
public bool HasSetValue;

}
加载更多回复(3)

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧