| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 658 人关注过本帖
标题:请教个 C# 的问题
取消只看楼主 加入收藏
弓虽人
Rank: 1
来 自:江苏南通
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-11-9
结帖率:100%
收藏
 问题点数:0 回复次数:0 
请教个 C# 的问题
public static C[] link_insert<P, C>(ref P parent, ref int count, string css)
        where P : Control
        where C : Control, new()
    {
        C[] childs = new C[count];
        for (int j = 0; j < count; j++)
        {
            childs[j] = new C();
            childs[j].CssClass = css + j.ToString();
            parent.Controls.Add(childs[j]);
        }
        return childs;
    }

这段代码,错在哪里?


如果把C的约束换成其他具体控件 就可以调用cssclass属性

public static C[] link_insert<P, C>(ref P parent, ref int count, string css)
        where P : Control
        where C : Button, new()
    {
        C[] childs = new C[count];
        for (int j = 0; j < count; j++)
        {
            childs[j] = new C();
            childs[j].CssClass = css + j.ToString();
            parent.Controls.Add(childs[j]);
        }
        return childs;
    }
比如这样写 就可以调用cssclass属性,不过这样写就限制了我传入的泛型c的类型
2008-11-10 12:52
快速回复:请教个 C# 的问题
数据加载中...
 
   



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

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