C#中void關鍵字是System.Void的別名;
可以將 void 用作方法(或本地函數(shù))的返回類型來指定該方法不返回值;
如果C#方法中沒有參數(shù),則不能將void用作參數(shù);這是與C語言不同的,C語言有 int func(void) 這樣的;
做一個winform示例看一下;文章來源:http://www.zghlxwxcb.cn/news/detail-695134.html
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;
}
}
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-695134.html
到了這里,關于C# void 關鍵字學習的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!