请帮助解决此错误 [英] Please help to solve this Error

查看:86
本文介绍了请帮助解决此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了此代码


使用系统;   
使用System.Collections.Generic ;   
使用System.Linq ;   
使用System.Text.RegularExpressions ;   

命名空间银行
{
    课程帐户
    {
        私人浮动余额;   
        公开无效存款(浮动金额)
        {
            balance + = amount ;   
        }
        公开 void 提款(浮动金额)
        {
            balance- = amount ;   
        }
        公开无效 TransferFunds(帐户目标,浮动金额)
        {
        }
        公众持股余额
        {
            得到
            {
                返回余额;   
            }
        }
        公共静态 void  testmethod()// 从这里我编写我想在Nunit中运行但在此Assert.AreEqual中也不运行的测试代码
        {
            帐户a1 =新帐户();   
            a1.Deposite( 200  .00f);   
            帐户a2 =新帐户();   
            a2.Deposite( 15  .00f);   
            a1.TransferFunds(a2, 100  .00f);   
            account.Equals( 250  .00f,a2.balance);   
            account.Equals( 100  .00f,a1.balance);   
        }
    }
} 




我收到此错误

错误1程序"C:\ Test Project \ ConsoleApplication2 \ ConsoleApplication2 \ obj \ Debug \ ConsoleApplication2.exe"不包含适合于入口点的静态"Main"方法ConsoleApplication2

方案

您正在编译代码以生成 exe 文件,然后需要一个入口点,即从中执行应用程序的方法开始.
如果要构建仅包含其他应用程序要使用的类的可执行文件,则应使用库项目,该项目会生成 dll 作为输出.

Main()方法是开始执行代码的方法.
您的控制台应用程序不包含一个.

testmethod()重命名为Main().
或者,如果您需要测试方法,则创建一个名为Main()的新静态方法,并在其中调用testMethod().


使用以下代码.它会解决问题:

 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text.RegularExpressions;

命名空间库
{
    课程帐户
    {
        私有 浮动余额;

        公开 无效存款(浮动金额)
        {
            余额+ =金额;
        }
        公共 无效取款(浮动金额)
        {
            余额-=金额;
        }
        公共 无效 TransferFunds(帐户目标,浮动数量)
        {
        }
        公共 浮动余额
        {
            获取
            {
                返回余额;
            }
        }
        公共 静态  void 主要
        {
            帐户a1 =  account();
            a1.Deposite( 200  .00f);
            帐户a2 =  account();
            a2.Deposite( 15  .00f);
            a1.TransferFunds(a2, 100  .00f);
            account.Equals( 250  .00f,a2.balance);
            account.Equals( 100  .00f,a1.balance);
        }
    }
} 


I have written this code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions ;

namespace bank
{
    class account
    {
        private float balance;
        public void Deposite(float amount)
        {
            balance+=amount;
        }
        public void withdraw(float amount)
        {
            balance-=amount;
        }
        public void TransferFunds(account destination, float amount)
        {
        }
        public float Balance
        {
            get
            {
                return balance;
            }
        }
        public static void testmethod()// from here i am writing testcode which i want to run in Nunit but in this Assert.AreEqual is also not supporting   
        {
            account a1 = new account();
            a1.Deposite(200.00f);
            account a2 = new account();
            a2.Deposite(15.00f);
            a1.TransferFunds(a2, 100.00f);
            account.Equals(250.00f, a2.balance);
            account.Equals(100.00f, a1.balance);
        }
    }
}




I am getting this error

Error 1 Program ''C:\Test Project\ConsoleApplication2\ConsoleApplication2\obj\Debug\ConsoleApplication2.exe'' does not contain a static ''Main'' method suitable for an entry point ConsoleApplication2

解决方案

You are compiling your code to produce an exe file, then an entry point is needed, i.e. a method from which the execution of your application starts.
If you want to build an executable file that only holds classes to be used by other applications, you should use a library project, that produces a dll as output.


Main() method is the method from where code execution starts.
Your console application doesn''t contain one.

Either rename testmethod() to Main().
Or, if you need the testmethod, Create a new static method called Main() and call testMethod() inside it.


Use the following code. it will resolve the problem:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions ;

namespace bank
{
    class account
    {
        private float balance;

        public void Deposite(float amount)
        {
            balance += amount;
        }
        public void withdraw(float amount)
        {
            balance -= amount;
        }
        public void TransferFunds(account destination, float amount)
        {
        }
        public float Balance
        {
            get
            {
                return balance;
            }
        }
        public static void Main
        {
            account a1 = new account();
            a1.Deposite(200.00f);
            account a2 = new account();
            a2.Deposite(15.00f);
            a1.TransferFunds(a2, 100.00f);
            account.Equals(250.00f, a2.balance);
            account.Equals(100.00f, a1.balance);
        }
    }
}


这篇关于请帮助解决此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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