using System;
using System.IO;
using System.Net.Sockets;
using System.Threading;
namespace TcpClientExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Client();
}
static void Client()
{
using (TcpClient client = new TcpClient("localhost", 51111))
using (NetworkStream n = client.GetStream())
{
BinaryWriter w = new BinaryWriter(n);
for (int i = 0; i < 10; i++)
{
w.Write("Hello");
Thread.Sleep(1000); // Give server time to start.
}
w.Flush();
Console.WriteLine(new BinaryReader(n).ReadString());
}
}
}
}
问题1,using是什么作用?
使用using,定义范围,在该范围