“公共无效"C#中的函数 [英] "public void" function in c#

查看:32
本文介绍了“公共无效"C#中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么当我尝试声明并使用public void"函数时,它给了我错误:

Can anyone tell me why when I try and declare and use a "public void" function it gives me the error:

 Expected class, delegate, enum, interface, or struct

我在开始时声明并正确设置了它,它不会调用我的主体.我已经研究过了,这似乎是可以做到的.

I have it declared at the start and have it set up correctly, and it won't call in my main body. I've researched it and this seems to be the ay to do it.

 public void receipt();

 namespace ConsoleApp
 {
      class Progam
      {
           static ... Main()
           {
                ...
           }
      }
 }

 public void receipt()
 {
      ...
 }

所以它需要在类程序"大括号中?

so it needs to be in the "class Program" Braces?

推荐答案

您必须声明包含在类或结构中的方法,因为方法不是根成员.

You must declare a method contained in a class or struct, because a method is not a root member.

这篇关于“公共无效"C#中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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