在C、c++和c#中,void意味着什么?

时间:2022-08-15 16:56:50

Looking to get the fundamentals on where the term "void" comes from, and why it is called void. The intention of the question is to assist someone who has no C experience, and is suddenly looking at a C-based codebase.

寻找“虚空”一词从何而来的基本原理,以及为什么它被称为虚空。这个问题的目的是帮助那些没有C经验的人,并突然查看基于C的代码基。

15 个解决方案

#1


198  

Basically it means "nothing" or "no type"

基本上它的意思是“无”或“无类型”

There are 3 basic ways that void is used:

使用void的基本方法有三种:

  1. Function argument: int myFunc(void) -- the function takes nothing.

    函数参数:int myFunc(void)——函数不需要任何东西。

  2. Function return value: void myFunc(int) -- the function returns nothing

    函数返回值:void myFunc(int)——函数不返回任何东西

  3. Generic data pointer: void* data -- 'data' is a pointer to data of unknown type, and cannot be dereferenced

    通用数据指针:void* data——“data”是指向未知类型的数据的指针,不能取消引用

Note: the void in a function argument is optional in C++, so int myFunc() is exactly the same as int myFunc(void), and it is left out completely in C#. It is always required for a return value.

注意:在c++中,函数参数中的void是可选的,因此int myFunc()与int myFunc(void)完全相同,并且在c#中完全被忽略。返回值总是需要它。

#2


23  

I have always taken it to mean absent. Here are four cases in the C language that matches to this use of absent

我总是把它理解为缺席。下面是C语言中与缺席用法相匹配的四种情况

  • R f(void) - Function parameters are absent
  • 没有函数参数
  • void f(P) - Return value is absent
  • 空f(P) -返回值不存在。
  • void *p - Type of what is pointed to is absent
  • void *p -指的是没有的类型
  • (void) p - Usage of value is absent
  • p -没有价值的使用

Other C descendants use it for other things. The D programming language uses it for cases where an initializer is absent

其他的C后代用它来做其他的事情。D编程语言在没有初始化器的情况下使用它

  • T t = void; - initializing value is absent
  • T T =无效;-缺少初始化值

#3


13  

It means "no value". You use void to indicate that a function doesn't return a value or that it has no parameters or both. Pretty much consistent with typical uses of word void in English.

它的意思是“没有价值”。使用void表示函数不返回值,或者没有参数,或者两者都没有。这与英语中“void”一词的典型用法非常一致。

#4


11  

There are two ways to use void:

使用void有两种方法:

void foo(void);

or

void *bar(void*);

The first indicates that no argument is being passed or that no argument is being returned.

第一个参数表示没有传递任何参数或没有返回任何参数。

The second tells the compiler that there is no type associated with the data effectively meaning that the you can't make use of the data pointed to until it is cast to a known type.

第二个命令告诉编译器,没有与数据有效关联的类型,这意味着在将数据转换为已知类型之前,您不能使用所指向的数据。

For example you will see void* used a lot when you have an interface which calls a function whose parameters can't be known ahead of time.

例如,当您有一个接口调用一个参数不能提前知道的函数时,您将看到void*大量使用。

For example, in the Linux Kernel when deferring work you will setup a function to be run at a latter time by giving it a pointer to the function to be run and a pointer to the data to be passed to the function:

例如,在Linux内核中,当延迟工作时,您将设置一个要在稍后运行的函数,给它一个要运行的函数指针和一个要传递给函数的数据指针:

struct _deferred_work {
sruct list_head mylist;
.worker_func = bar;
.data        = somedata;
} deferred_work;

Then a kernel thread goes over a list of deferred work and when it get's to this node it effectively executes:

然后,一个内核线程经过一个递延工作列表,当它到达这个节点时,它会有效地执行:

bar(somedata);

Then in bar you have:

然后在酒吧里:

void bar(void* mydata) {
    int *data = mydata;
    /* do something with data */;
}

#5


4  

It indicates the absence of a return value in a function.

它表示函数中没有返回值。

Some languages have two sorts of subroutines: procedures and functions. Procedures are just a sequence of operations, whereas a function is a sequence of operations that return a result.

有些语言有两种子程序:过程和函数。过程只是操作序列,而函数是返回结果的操作序列。

In C and its derivatives, the difference between the two is not explicit. Everything is basically a function. the void keyword indicates that it's not an "actual" function, since it doesn't return a value.

在C和它的导数中,两者之间的区别是不明确的。一切基本上都是一个函数。void关键字表明它不是“实际的”函数,因为它不返回值。

#6


3  

Think of void as the "empty structure". Let me explain.

把虚空想象成“空结构”。让我解释一下。

Every function takes a sequence of parameters, where each parameter has a type. In fact, we could package up the parameters into a structure, with the structure slots corresponding to the parameters. This makes every function have exactly one argument. Similarly, functions produce a result, which has a type. It could be a boolean, or it could be float, or it could be a structure, containing an arbitrary set of other typed values. If we want a languge that has multiple return values, it is easy to just insist they be packaged into a structure. In fact, we could always insist that a function returned a structure. Now every function takes exactly one argument, and produces exactly one value.

每个函数都有一个参数序列,其中每个参数都有一个类型。实际上,我们可以将参数打包成一个结构,结构槽对应于参数。这使得每个函数只有一个参数。类似地,函数产生一个具有类型的结果。它可以是布尔值,也可以是浮点值,也可以是一个结构,包含一组其他类型值。如果我们想要一个具有多个返回值的语言,那么很容易坚持将它们打包到一个结构中。事实上,我们可以一直坚持一个函数返回一个结构。现在每个函数都只需要一个参数,只产生一个值。

Now, what happens when I need a function that produces "no" value? Well, consider what I get when I form a struct with 3 slots: it holds 3 values. When I have 2 slots, it holds two values. When it has one slot, one value. And when it has zero slots, it holds... uh, zero values, or "no" value". So, I can think of a function returning void as returning a struct containing no values. You can even decide that "void" is just a synonym for the type represented by the empty structure, rather than a keyword in the language (maybe its just a predefined type :)

现在,当我需要一个产生“不”值的函数时,会发生什么?当我构造一个有3个槽的结构时,我得到了什么:它包含3个值。当我有两个槽时,它有两个值。当它有一个槽时,一个值。当它有零位时,它会保持…零值,或者“没有”值。因此,我可以将返回void的函数看作返回一个不包含值的结构体。您甚至可以决定“void”只是空结构表示的类型的同义词,而不是语言中的关键字(可能只是预定义类型:)

Similarly, I can think of a function requiring no values as accepting an empty structure, e.g., "void".

类似地,我可以将不需要值的函数看作接受一个空结构,例如“void”。

I can even implement my programming language this way. Passing a void value takes up zero bytes, so passing void values is just a special case of passing other values of arbitrary size. This makes it easy for the compiler to treat the "void" result or argument. You probably want a langauge feature that can throw a function result away; in C, if you call the non-void result function foo in the following statement: foo(...); the compiler knows that foo produces a result and simply ignores it. If void is a value, this works perfectly and now "procedures" (which are just an adjective for a function with void result) are just trivial special cases of general functions.

我甚至可以用这种方式实现我的编程语言。传递一个void值占用零字节,所以传递void值只是传递其他任意大小的值的特殊情况。这使得编译器很容易处理“void”结果或参数。你可能想要的是一种语言功能,可以把一个函数的结果扔掉;在C中,如果在以下语句中调用非void结果函数foo: foo(…);编译器知道foo生成一个结果并忽略它。如果void是一个值,那么它就可以很好地工作,而现在的“过程”(它只是一个带有void结果的函数的形容词)只是一般函数的普通特例。

Void* is a bit funnier. I don't think the C designers thought of void in the above way; they just created a keyword. That keyword was available when somebody needed a point to an arbitrary type, thus void* as the idiom in C. It actually works pretty well if you interpret void as an empty structure. A void* pointer is the address of a place where that empty structure has been put.

Void*有点有趣。我不认为C的设计者是这样认为的;他们只是创造了一个关键字。当某人需要一个指向任意类型的点时,就可以使用这个关键字,因此就像c中的习语void*一样。空*指针是放置空结构的位置的地址。

Casts from void* to T* for other types T, also work out with this perspective. Pointer casts are a complete cheat that work on most common architectures to take advantage of the fact that if a compound type T has an element with subtype S placed physically at the beginning of T in its storage layout, then casting S* to T* and vice versa using the same physical machine address tends to work out, since most machine pointers have a single representation. Replacing the type S by the type void gives exactly the same effect, and thus casting to/from void* works out.

对于其他类型的T,也可以从void*转换为T*,并使用此透视图进行处理。指针类型转换是一个完整的欺骗,最常见的工作架构利用这一事实,如果一种化合物类型T的元素与亚型S放置身体的T存储布局,然后铸造年代* T *反之亦然使用相同的物理机器地址往往奏效,因为大多数机器的指针有一个表示。用类型void替换类型S会产生完全相同的效果,因此对void*进行/from的强制转换是可行的。

The PARLANSE programming language implements the above ideas pretty closely. We goofed in its design, and didn't pay close attention to "void" as a return type and thus have langauge keywords for procedure. Its mostly just a simple syntax change but its one of things you don't get around to once you get a large body working code in a language.

PARLANSE编程语言非常紧密地实现了上述思想。我们在它的设计中犯了错误,并没有注意到“void”作为返回类型,因此有了langauge关键字的过程。它主要是一个简单的语法变化,但它是你在一种语言中得到一个庞大的身体工作代码时所不能得到的东西之一。

#7


2  

In c# you'd use the void keyword to indicate that a method does not return a value:

在c#中,您将使用void关键字来指示方法不返回值:

public void DoSomeWork()
{
//some work
}

#8


2  

Three usage cases for void:

三种无效用例:

  1. Function signatures. void foo(int bar) does not return a value. int bar(void) does not take any parameters but this is usually expressed with empty argument list: int bar(). Usage of the void keyword here corresponds to its meaning in English.

    函数签名。void foo(int bar)不返回值。int bar(void)不接受任何参数,但通常用空的参数列表表示:int bar()。这里void关键字的用法对应于它在英语中的意思。

  2. Generic top-type pointer void * that points to unspecified data and cannot be dereferenced. Here the meaning of void is different from other meanings of void: universal type vs. no type.

    泛型*指针void *,指向未指定的数据,不能被取消引用。在这里,虚空的含义不同于虚空的其他含义:普遍型与无型。

  3. In casts such as (void) new Foo(this) to signify that the return value is deliberately thrown away. Here the keyword usage also matches its meaning in English.

    在(void) new Foo(this)等类型的类型转换中,表示故意丢弃返回值。在这里,关键字的用法也与它在英语中的意思相匹配。

Cases 1 and 2 were already covered by @Gerald but case 3 has not been addressed yet.

案例1和案例2已经被@Gerald覆盖,但是案例3还没有被解决。

#9


2  

If you're explaining the concept to a beginner, it might be helpful to use an analogy. The use of void in all these cases is analogous in meaning to a page in a book which has the following words, "This page left intentionally blank." It is to differentiate to the compiler between something which should be flagged as an error, versus a type which is intentionally to be left blank because that is the behavior you want.

如果你正在向初学者解释这个概念,用一个类比可能会有帮助。在所有这些情况下,“空”的使用都类似于书中的一页,书中有这样一句话:“这一页故意空着。”它是对编译器进行区分,区分应该标记为错误的东西和故意留空的类型,因为这是您想要的行为。

It always appears in code where normally you would expect to see a type appear, such as a return type or a pointer type. This is why in C#, void maps to an actual CLR type, System.Void because it is a type in itself.

它总是出现在代码中,通常您希望看到类型出现,例如返回类型或指针类型。这就是为什么在c#中,void映射到实际的CLR类型,系统。Void,因为它本身就是一种类型。

Some programming languages never developed the concept of void, just like some human cultures never invented the concept of the number zero. Void represents the same advancement in a programming language as the concept of zero represents to human language.

一些编程语言从未开发出void的概念,就像某些人类文化从未发明数字零的概念一样。Void代表了编程语言中与zero代表人类语言的概念一样的进步。

#10


1  

It means "no value". You use void to indicate that a function doesn't return a value or that it has no parameters or both.It's much consistent with typical uses of word void in English.

它的意思是“没有价值”。使用void表示函数不返回值,或者没有参数,或者两者都没有。这与英语中“void”一词的典型用法非常一致。

Void should not be confused with null. Null means for the variable whose address is on stack, the value on the heap for that address is empty.

不应将Void与null混淆。Null表示地址在堆栈上的变量,该地址在堆上的值为空。

#11


0  

Void is used only in method signatures. For return types it means method will not return anything to the calling code. For parameters it means, no parameters are passed to the method

Void只在方法签名中使用。对于返回类型,它意味着方法不会向调用代码返回任何内容。对于参数,意味着没有参数传递给方法

e.g.

如。

void MethodThatReturnsAndTakesVoid(void)
{
// Method body
}

In C# we can omit the void for parameters and can write the above code as:

在c#中,我们可以省略参数的空白,可以将上面的代码写成:

void MethodThatReturnsAndTakesVoid()
{
// Method body
}

Void should not be confused with null. Null means for the variable whose address is on stack, the value on the heap for that address is empty.

不应将Void与null混淆。Null表示地址在堆栈上的变量,该地址在堆上的值为空。

#12


0  

Void is a incomplete type which by deffinition can't be an lvalue. What means it can't get assigned a value.

Void是一个不完整的类型,由deffinition不可能是一个lvalue。也就是说它不能被赋值。

So it also can't hold any value.

所以它也不能保留任何值。

#13


-1  

void mean that you won't be returning any value form the function or method

void表示您不会从函数或方法返回任何值

#14


-1  

Void means no value required in return type from a function in all of three language.

Void表示三种语言中的函数返回类型中不需要任何值。

#15


-1  

Void is the equivalent of Visual Basic's Sub.

Void相当于Visual Basic的Sub。

#1


198  

Basically it means "nothing" or "no type"

基本上它的意思是“无”或“无类型”

There are 3 basic ways that void is used:

使用void的基本方法有三种:

  1. Function argument: int myFunc(void) -- the function takes nothing.

    函数参数:int myFunc(void)——函数不需要任何东西。

  2. Function return value: void myFunc(int) -- the function returns nothing

    函数返回值:void myFunc(int)——函数不返回任何东西

  3. Generic data pointer: void* data -- 'data' is a pointer to data of unknown type, and cannot be dereferenced

    通用数据指针:void* data——“data”是指向未知类型的数据的指针,不能取消引用

Note: the void in a function argument is optional in C++, so int myFunc() is exactly the same as int myFunc(void), and it is left out completely in C#. It is always required for a return value.

注意:在c++中,函数参数中的void是可选的,因此int myFunc()与int myFunc(void)完全相同,并且在c#中完全被忽略。返回值总是需要它。

#2


23  

I have always taken it to mean absent. Here are four cases in the C language that matches to this use of absent

我总是把它理解为缺席。下面是C语言中与缺席用法相匹配的四种情况

  • R f(void) - Function parameters are absent
  • 没有函数参数
  • void f(P) - Return value is absent
  • 空f(P) -返回值不存在。
  • void *p - Type of what is pointed to is absent
  • void *p -指的是没有的类型
  • (void) p - Usage of value is absent
  • p -没有价值的使用

Other C descendants use it for other things. The D programming language uses it for cases where an initializer is absent

其他的C后代用它来做其他的事情。D编程语言在没有初始化器的情况下使用它

  • T t = void; - initializing value is absent
  • T T =无效;-缺少初始化值

#3


13  

It means "no value". You use void to indicate that a function doesn't return a value or that it has no parameters or both. Pretty much consistent with typical uses of word void in English.

它的意思是“没有价值”。使用void表示函数不返回值,或者没有参数,或者两者都没有。这与英语中“void”一词的典型用法非常一致。

#4


11  

There are two ways to use void:

使用void有两种方法:

void foo(void);

or

void *bar(void*);

The first indicates that no argument is being passed or that no argument is being returned.

第一个参数表示没有传递任何参数或没有返回任何参数。

The second tells the compiler that there is no type associated with the data effectively meaning that the you can't make use of the data pointed to until it is cast to a known type.

第二个命令告诉编译器,没有与数据有效关联的类型,这意味着在将数据转换为已知类型之前,您不能使用所指向的数据。

For example you will see void* used a lot when you have an interface which calls a function whose parameters can't be known ahead of time.

例如,当您有一个接口调用一个参数不能提前知道的函数时,您将看到void*大量使用。

For example, in the Linux Kernel when deferring work you will setup a function to be run at a latter time by giving it a pointer to the function to be run and a pointer to the data to be passed to the function:

例如,在Linux内核中,当延迟工作时,您将设置一个要在稍后运行的函数,给它一个要运行的函数指针和一个要传递给函数的数据指针:

struct _deferred_work {
sruct list_head mylist;
.worker_func = bar;
.data        = somedata;
} deferred_work;

Then a kernel thread goes over a list of deferred work and when it get's to this node it effectively executes:

然后,一个内核线程经过一个递延工作列表,当它到达这个节点时,它会有效地执行:

bar(somedata);

Then in bar you have:

然后在酒吧里:

void bar(void* mydata) {
    int *data = mydata;
    /* do something with data */;
}

#5


4  

It indicates the absence of a return value in a function.

它表示函数中没有返回值。

Some languages have two sorts of subroutines: procedures and functions. Procedures are just a sequence of operations, whereas a function is a sequence of operations that return a result.

有些语言有两种子程序:过程和函数。过程只是操作序列,而函数是返回结果的操作序列。

In C and its derivatives, the difference between the two is not explicit. Everything is basically a function. the void keyword indicates that it's not an "actual" function, since it doesn't return a value.

在C和它的导数中,两者之间的区别是不明确的。一切基本上都是一个函数。void关键字表明它不是“实际的”函数,因为它不返回值。

#6


3  

Think of void as the "empty structure". Let me explain.

把虚空想象成“空结构”。让我解释一下。

Every function takes a sequence of parameters, where each parameter has a type. In fact, we could package up the parameters into a structure, with the structure slots corresponding to the parameters. This makes every function have exactly one argument. Similarly, functions produce a result, which has a type. It could be a boolean, or it could be float, or it could be a structure, containing an arbitrary set of other typed values. If we want a languge that has multiple return values, it is easy to just insist they be packaged into a structure. In fact, we could always insist that a function returned a structure. Now every function takes exactly one argument, and produces exactly one value.

每个函数都有一个参数序列,其中每个参数都有一个类型。实际上,我们可以将参数打包成一个结构,结构槽对应于参数。这使得每个函数只有一个参数。类似地,函数产生一个具有类型的结果。它可以是布尔值,也可以是浮点值,也可以是一个结构,包含一组其他类型值。如果我们想要一个具有多个返回值的语言,那么很容易坚持将它们打包到一个结构中。事实上,我们可以一直坚持一个函数返回一个结构。现在每个函数都只需要一个参数,只产生一个值。

Now, what happens when I need a function that produces "no" value? Well, consider what I get when I form a struct with 3 slots: it holds 3 values. When I have 2 slots, it holds two values. When it has one slot, one value. And when it has zero slots, it holds... uh, zero values, or "no" value". So, I can think of a function returning void as returning a struct containing no values. You can even decide that "void" is just a synonym for the type represented by the empty structure, rather than a keyword in the language (maybe its just a predefined type :)

现在,当我需要一个产生“不”值的函数时,会发生什么?当我构造一个有3个槽的结构时,我得到了什么:它包含3个值。当我有两个槽时,它有两个值。当它有一个槽时,一个值。当它有零位时,它会保持…零值,或者“没有”值。因此,我可以将返回void的函数看作返回一个不包含值的结构体。您甚至可以决定“void”只是空结构表示的类型的同义词,而不是语言中的关键字(可能只是预定义类型:)

Similarly, I can think of a function requiring no values as accepting an empty structure, e.g., "void".

类似地,我可以将不需要值的函数看作接受一个空结构,例如“void”。

I can even implement my programming language this way. Passing a void value takes up zero bytes, so passing void values is just a special case of passing other values of arbitrary size. This makes it easy for the compiler to treat the "void" result or argument. You probably want a langauge feature that can throw a function result away; in C, if you call the non-void result function foo in the following statement: foo(...); the compiler knows that foo produces a result and simply ignores it. If void is a value, this works perfectly and now "procedures" (which are just an adjective for a function with void result) are just trivial special cases of general functions.

我甚至可以用这种方式实现我的编程语言。传递一个void值占用零字节,所以传递void值只是传递其他任意大小的值的特殊情况。这使得编译器很容易处理“void”结果或参数。你可能想要的是一种语言功能,可以把一个函数的结果扔掉;在C中,如果在以下语句中调用非void结果函数foo: foo(…);编译器知道foo生成一个结果并忽略它。如果void是一个值,那么它就可以很好地工作,而现在的“过程”(它只是一个带有void结果的函数的形容词)只是一般函数的普通特例。

Void* is a bit funnier. I don't think the C designers thought of void in the above way; they just created a keyword. That keyword was available when somebody needed a point to an arbitrary type, thus void* as the idiom in C. It actually works pretty well if you interpret void as an empty structure. A void* pointer is the address of a place where that empty structure has been put.

Void*有点有趣。我不认为C的设计者是这样认为的;他们只是创造了一个关键字。当某人需要一个指向任意类型的点时,就可以使用这个关键字,因此就像c中的习语void*一样。空*指针是放置空结构的位置的地址。

Casts from void* to T* for other types T, also work out with this perspective. Pointer casts are a complete cheat that work on most common architectures to take advantage of the fact that if a compound type T has an element with subtype S placed physically at the beginning of T in its storage layout, then casting S* to T* and vice versa using the same physical machine address tends to work out, since most machine pointers have a single representation. Replacing the type S by the type void gives exactly the same effect, and thus casting to/from void* works out.

对于其他类型的T,也可以从void*转换为T*,并使用此透视图进行处理。指针类型转换是一个完整的欺骗,最常见的工作架构利用这一事实,如果一种化合物类型T的元素与亚型S放置身体的T存储布局,然后铸造年代* T *反之亦然使用相同的物理机器地址往往奏效,因为大多数机器的指针有一个表示。用类型void替换类型S会产生完全相同的效果,因此对void*进行/from的强制转换是可行的。

The PARLANSE programming language implements the above ideas pretty closely. We goofed in its design, and didn't pay close attention to "void" as a return type and thus have langauge keywords for procedure. Its mostly just a simple syntax change but its one of things you don't get around to once you get a large body working code in a language.

PARLANSE编程语言非常紧密地实现了上述思想。我们在它的设计中犯了错误,并没有注意到“void”作为返回类型,因此有了langauge关键字的过程。它主要是一个简单的语法变化,但它是你在一种语言中得到一个庞大的身体工作代码时所不能得到的东西之一。

#7


2  

In c# you'd use the void keyword to indicate that a method does not return a value:

在c#中,您将使用void关键字来指示方法不返回值:

public void DoSomeWork()
{
//some work
}

#8


2  

Three usage cases for void:

三种无效用例:

  1. Function signatures. void foo(int bar) does not return a value. int bar(void) does not take any parameters but this is usually expressed with empty argument list: int bar(). Usage of the void keyword here corresponds to its meaning in English.

    函数签名。void foo(int bar)不返回值。int bar(void)不接受任何参数,但通常用空的参数列表表示:int bar()。这里void关键字的用法对应于它在英语中的意思。

  2. Generic top-type pointer void * that points to unspecified data and cannot be dereferenced. Here the meaning of void is different from other meanings of void: universal type vs. no type.

    泛型*指针void *,指向未指定的数据,不能被取消引用。在这里,虚空的含义不同于虚空的其他含义:普遍型与无型。

  3. In casts such as (void) new Foo(this) to signify that the return value is deliberately thrown away. Here the keyword usage also matches its meaning in English.

    在(void) new Foo(this)等类型的类型转换中,表示故意丢弃返回值。在这里,关键字的用法也与它在英语中的意思相匹配。

Cases 1 and 2 were already covered by @Gerald but case 3 has not been addressed yet.

案例1和案例2已经被@Gerald覆盖,但是案例3还没有被解决。

#9


2  

If you're explaining the concept to a beginner, it might be helpful to use an analogy. The use of void in all these cases is analogous in meaning to a page in a book which has the following words, "This page left intentionally blank." It is to differentiate to the compiler between something which should be flagged as an error, versus a type which is intentionally to be left blank because that is the behavior you want.

如果你正在向初学者解释这个概念,用一个类比可能会有帮助。在所有这些情况下,“空”的使用都类似于书中的一页,书中有这样一句话:“这一页故意空着。”它是对编译器进行区分,区分应该标记为错误的东西和故意留空的类型,因为这是您想要的行为。

It always appears in code where normally you would expect to see a type appear, such as a return type or a pointer type. This is why in C#, void maps to an actual CLR type, System.Void because it is a type in itself.

它总是出现在代码中,通常您希望看到类型出现,例如返回类型或指针类型。这就是为什么在c#中,void映射到实际的CLR类型,系统。Void,因为它本身就是一种类型。

Some programming languages never developed the concept of void, just like some human cultures never invented the concept of the number zero. Void represents the same advancement in a programming language as the concept of zero represents to human language.

一些编程语言从未开发出void的概念,就像某些人类文化从未发明数字零的概念一样。Void代表了编程语言中与zero代表人类语言的概念一样的进步。

#10


1  

It means "no value". You use void to indicate that a function doesn't return a value or that it has no parameters or both.It's much consistent with typical uses of word void in English.

它的意思是“没有价值”。使用void表示函数不返回值,或者没有参数,或者两者都没有。这与英语中“void”一词的典型用法非常一致。

Void should not be confused with null. Null means for the variable whose address is on stack, the value on the heap for that address is empty.

不应将Void与null混淆。Null表示地址在堆栈上的变量,该地址在堆上的值为空。

#11


0  

Void is used only in method signatures. For return types it means method will not return anything to the calling code. For parameters it means, no parameters are passed to the method

Void只在方法签名中使用。对于返回类型,它意味着方法不会向调用代码返回任何内容。对于参数,意味着没有参数传递给方法

e.g.

如。

void MethodThatReturnsAndTakesVoid(void)
{
// Method body
}

In C# we can omit the void for parameters and can write the above code as:

在c#中,我们可以省略参数的空白,可以将上面的代码写成:

void MethodThatReturnsAndTakesVoid()
{
// Method body
}

Void should not be confused with null. Null means for the variable whose address is on stack, the value on the heap for that address is empty.

不应将Void与null混淆。Null表示地址在堆栈上的变量,该地址在堆上的值为空。

#12


0  

Void is a incomplete type which by deffinition can't be an lvalue. What means it can't get assigned a value.

Void是一个不完整的类型,由deffinition不可能是一个lvalue。也就是说它不能被赋值。

So it also can't hold any value.

所以它也不能保留任何值。

#13


-1  

void mean that you won't be returning any value form the function or method

void表示您不会从函数或方法返回任何值

#14


-1  

Void means no value required in return type from a function in all of three language.

Void表示三种语言中的函数返回类型中不需要任何值。

#15


-1  

Void is the equivalent of Visual Basic's Sub.

Void相当于Visual Basic的Sub。