怎么调用其他库里的结构和函数
我的主程序Program.cs里面有public struct Message
{
private readonly string userName;
private readonly string content;
private readonly DateTime postDate;
public Message(string userName, string content)
{
this.userName = userName;
this.content = content;
this.postDate = DateTime.Now;
}
public Message(string content) : this("System", content) { }
public string UserName
{
get { return userName; }
}
public string Content
{
get { return content; }
}
public DateTime PostDate
{
get { return postDate; }
}
public override string ToString()
{
return String.Format("{0}[{1}]:\r\n{2}\r\n", userName, postDate, content);
}
}
然后我在Form2.cs里面调用
// 发送消息
private void btnSend_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(txtContent.Text))
{
MessageBox.Show("请输入内容!");
txtContent.Clear();
txtContent.Focus();
return;
}
Message msg = new Message(userName, txtMessage.Text);//这里就出错了
if (talker.SendMessage(msg))
{
错误报告:E:\ProgramFiles\Projects\Bruce\Bruce\Form2.cs(94,31): 错误 CS0143: 类型“System.Windows.Forms.Message”未定义构造函数
请问是为什么?我正在用socket编聊天程序。