| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1315 人关注过本帖
标题:c#结构体中的数组赋值问题
只看楼主 加入收藏
caitou123
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-10-28
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
c#结构体中的数组赋值问题
结构体定义为
struct modelshape//图案的数据类型
        {
             int[,] model=new int[4,4];
        };
以下为结构体数组赋值
modelshape[] modeltype = new modelshape[]{{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0},{0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0},{1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0},
            {1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0},{0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0},{1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},{0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},{1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
            {1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0},{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0},{1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0},{1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},
            {0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0},{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,1,0,0,1,1,1,0,0,1,0,0,0,0,0,0},{1,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0},{1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0},{0,0,1,0,0,0,1,0,1,1,1,0,0,0,0,0},{1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0}};

上面是定义一个结构体数组,大小为27,并为其中每个结构体赋值
但在程序赋值的时候报错了,应该怎么处理
搜索更多相关主题的帖子: 结构体 图案 
2011-10-28 16:23
serious
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:81
专家分:497
注 册:2009-8-18
收藏
得分:20 
在C#中你的代码不是正确。
可能你可以用这个解答:
程序代码:
struct modelshape
{
    public int[,] model;
};

static modelshape[] ConvertToModelShapeCollection(int[][] array)
{
    return array.Select(line => new modelshape { model = Enumerable.Range(0, 16).Aggregate(new int[4, 4], (a, n) => { a[n / 4, n % 4] = line[n]; return a; }) }).ToArray();
}

static void Main()
{
    modelshape[] modeltype = ConvertToModelShapeCollection(new []{
                                                                    new[]{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
                                                                    new[]{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0},
                                                                    new[]{0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0}});
}

2011-10-29 06:54
快速回复:c#结构体中的数组赋值问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055572 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved