我为这个愚蠢的问题表示歉意,但我是C#的新手,并且无法从与此错误相关的其他问题中找到帮助。C#对象不包含方法的定义
我创建了一个名为“Sender”的类,但是当我实例化一个对象时,我无法访问我的方法。当我尝试调用我的方法时,出现错误:“对象不包含sendMessage的定义。”我不知道我哪里错了。请指向正确的方向。
感谢您的帮助!
这是我的发件人类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
namespace CS5200_HW1_GUI
{
public class Sender
{
private UdpClient myUdpClient;
private IPEndPoint localEP;
string ipAddress = "129.123.41.1";
string _port = "12001";
public void sendMessage()
{
}
// byte[] sendBuffer = Encoding.Unicode.GetBytes(command);
// int result = myUdpClient.Send(sendBuffer, sendBuffer.Length, localEP);
}
}
这就是我想要调用方法:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
namespace CS5200_HW1_GUI
{
public partial class Form1 : Form
{
//private UdpClient myUdpClient;
IPEndPoint localEP = new IPEndPoint(IPAddress.Any, 0);
string command = string.Empty;
string newWord = String.Empty;
string guess = String.Empty;
string dashes = String.Empty;
string newAddress = string.Empty;
string newPort = string.Empty;
int score = 0;
int length = 0;
StringBuilder sb = new StringBuilder();
Random random = new Random();
Sender sender = new Sender();
private void button1_Click(object sender, EventArgs e)
{
command = "NewGame";
sender.sendMessage(command); //I get the error here
newWord = receiver.receiveMessage();
length = newWord.Length;
}
}
}
sendMessage方法不接受参数应sendMessage()不sendMessage(命令) – Sorceri 2014-09-05 16:39:02