我有两个文件。一个是Scenario2_Client.Xaml.cs,另一个是test.cs。我想在Scenario2_Client.Xaml.cs中的方法之一内调用EchoClient类。
在test.cs中,我有以下代码:
public class EchoClient
public static void Main() {
try {
TcpClient client = new TcpClient("139.169.63.130", 9999);
StreamReader reader = new StreamReader(client.GetStream());
StreamWriter writer = new StreamWriter(client.GetStream());
string s = string.Empty;
while(!s.Equals("Exit")) {
Console.WriteLine("TCP Client connected....");
Console.Write("Enter a string or number to send to the server: ");
s = Console.ReadLine();
Console.WriteLine();
writer.WriteLine(s);
writer.Flush();
string server_string = reader.ReadLine();
Console.WriteLine(server_string);
}
reader.Close();
writer.Close();
client.Close();
} catch(Exception e) {
Console.WriteLine(e);
}
}
}
在Scenario2_Client.Xaml.cs上具有以下内容:
public sealed partial class Scenario2_Client : Page
{
// code
// code
private void RemoveValueChangedHandler() // this is where I want to add EchoClient class
{
ValueChangedSubscribeToggle.Content = "Subscribe to value changes";
if (subscribedForNotifications)
{
registeredCharacteristic.ValueChanged -= Characteristic_ValueChanged;
registeredCharacteristic = null;
subscribedForNotifications = false;
}
}
...
}
有关如何执行此操作的任何建议? 谢谢。
答案 0 :(得分:0)
如果我正确理解了,我建议您执行以下步骤:
在执行这些步骤之前,可能有必要查看一些有关如何创建类及其代表的教程。有很多好的资源。 https://www.c-sharpcorner.com/UploadFile/mkagrahari/introduction-to-object-oriented-programming-concepts-in-C-Sharp/