Client.exe'不包含适用于入口点的静态"Main"方法 [英] Client.exe' does not contain a static 'Main' method suitable for an entry point

查看:104
本文介绍了Client.exe'不包含适用于入口点的静态"Main"方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;


namespace Server_Client
{
    class client
    {
        static void Connect(String server, String message)
        {
            try
            {
                // Create a TcpClient.
                // Note, for this client to work you need to have a TcpServer 
                // connected to the same address as specified by the server, port
                // combination.
                Int32 port = 13000;
                TcpClient client = new TcpClient(server, port);

                // Translate the passed message into ASCII and store it as a Byte array.
                Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);

                // Get a client stream for reading and writing.
                //  Stream stream = client.GetStream();

                NetworkStream stream = client.GetStream();

                // Send the message to the connected TcpServer. 
                stream.Write(data, 0, data.Length);

                Console.WriteLine("Sent: {0}", message);

                // Receive the TcpServer.response.

                // Buffer to store the response bytes.
                data = new Byte[256];

                // String to store the response ASCII representation.
                String responseData = String.Empty;

                // Read the first batch of the TcpServer response bytes.
                Int32 bytes = stream.Read(data, 0, data.Length);
                responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                Console.WriteLine("Received: {0}", responseData);

                // Close everything.
                client.Close();
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("ArgumentNullException: {0}", e);
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }

            Console.WriteLine("\n Press Enter to continue...");
            Console.Read();
        }
    }
}




这是MSDN的代码形式. 我正在研究c#,有人可以帮我解决这个错误吗?
错误:Client.exe"不包含适用于入口点的静态"Main"方法

谢谢
NN




This is code form MSDN.....
I am studying c# can anyone help me to get ride of this error
error : Client.exe'' does not contain a static ''Main'' method suitable for an entry point

Thanks
NN

推荐答案

控制台/Windows应用程序需要入口点.在Web应用程序/网站中,将出现启动页面/登录页面将是入口点.

因此,任何一个类文件(如果有多个类文件)都必须有静态的"Main"方法.
在您的班级中添加以下代码,您的应用程序将运行
Console/Windows Application requires entry point. Where as in web application/web site, there will be start up page/Login page will be entry point.

So, there must be static "Main" method in any one of class file (if you have multiple class files).
Add below code in your class, your application will work
static void Main(string[] args){
     //call your method
 }


每个控制台应用程序都应具有一个入口点来执行该应用程序.在C#中,它是通过Main方法定义的.因此,您需要包含一个方法名称为"main"的方法,并且可能不是完美的语法跟随者.

例如:请在类中添加以下代码.
Each and every console application should have an entry point to execute the application. In C# it is defined by Main method. So you need to include a method which has a method name as "main" and may not be a perfect syntax follower.

For example: Please add the following code inside the the class.
static void Main()
{
   client.Connect("server name", "message");
}



HTH,
Sham _



HTH,
Sham_


这篇关于Client.exe'不包含适用于入口点的静态"Main"方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆