首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#中调用带参数的种

2013-01-08 
C#中调用带参数的类[解决办法]引用带参数的类真能想那分明是构造函数public Post(int Id,string title){th

C#中调用带参数的类


[解决办法]
引用
带参数的类

真能想

那分明是构造函数



   public Post(int Id,string title)
        {
            this.ID = Id;
            this.Title = title;
        }
        public int ID { get; set; }
        public int CategoryID { get; set; }

        public string Title { get; set; }
        public string Summary { get; set; }
        public string Alias { get; set; }
        public string Content { get; set; }
        public DateTime CreateTime { get; set; }

        public Category Category { get; set; }
        public ICollection<Tag> Tags { get; set; }
        public ICollection<Comment> Coments { get; set; }
    }


    Post post=new Post(1,"title")


[解决办法]
public void fangfa() ; 
public gouzao();

你那是构造。
[解决办法]


 public class Post


    {
        public Post(int Id,string title)
        {
            this.ID = Id;
            this.Title = title;
        }

        public int ID { get; set; }
        public int CategoryID { get; set; }

        public string Title { get; set; }
        public string Summary { get; set; }
        public string Alias { get; set; }
        public string Content { get; set; }
        public DateTime CreateTime { get; set; }

        public Category Category { get; set; }
        public ICollection<Tag> Tags { get; set; }
        public ICollection<Comment> Coments { get; set; }
    }

Post post=new Post(1,"title")


[解决办法]
解决办法有2种:
方法一,在Program中的入口实例化构造函数就必须传参:

 static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Route());
        }
    }

方法二:
 
 
public partial class Route : Form
    {
        public List<string> picCount = new List<string>();
        public Route(string statusInfo)
        {
            InitializeComponent();
            this.listBox1.Focus();
            this.statusInfo = statusInfo;
        }
    }

public class ThreadWithState
    {
        public void ThreadProc()
        {
            //这边报错, 没用0个参数          


            Route r = new Route("");
            //请问这边该怎么改?
            r.picCount...
        }
    }


类Route中没有默认的构造函数引起的,只要添加默认的构造函数就可以了。 

热点排行