C#中void关键字是System.Void的别名;
可以将 void 用作方法(或本地函数)的返回类型来指定该方法不返回值;
如果C#方法中没有参数,则不能将void用作参数;这是与C语言不同的,C语言有 int func(void) 这样的;
做一个winform示例看一下;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace vtest
- {
- public partial class Form1 : Form
- {
- private int c;
-
- public Form1()
- {
- InitializeComponent();
- }
-
- private void Form1_Load(object sender, EventArgs e)
- {
- int a = 100;
- int b = 5;
- sum(a, b);
- textBox1.Text = c.ToString();
- }
-
- private void sum(int a, int b)
- {
- c = a + b;
- }
- }
- }
