c#中void_C#中的void关键字

c#中void

C#void关键字 (C# void keyword)

In C#, void is a keyword. a void is a reference type of data type, it is used to specify the return type of a method in C#.

在C#中, void是关键字。 void是数据类型的引用类型,它用于指定C#中方法的返回类型。

void keyword is an alias of System.Void.

void关键字是System.Void的别名。

Note: If there is no parameter in a C# method, void cannot be used as a parameter.

注意:如果C#方法中没有参数,则不能将void用作参数。

Syntax:

句法:

public void function_name([parameters])
{
	//body of the function
}

C#代码演示void关键字示例 (C# code to demonstrate example of void keyword)

using System;
using System.Text;

namespace Test
{
    class Example
    {
        public void printText()
        {
            Console.WriteLine("Hello world!");
        }
        public void sum(int a, int b)
        {
            Console.WriteLine("sum = " + (a + b));
        }

    };
	
    class Program
    {
        static void Main(string[] args)
        {
            //calling functions
            Example ex = new Example();
            ex.printText();
            ex.sum(10, 20);

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

输出量

Hello world!
sum = 30


翻译自: https://www.includehelp.com/dot-net/void-keyword-in-c-sharp.aspx

c#中void

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值