AFAIK void
在编程语言方面没有任何意义。那么为什么在.Net框架中它被声明为struct
?为什么返回类型void在.NET中声明为struct?
using System.Runtime.InteropServices;
namespace System
{
/// <summary>
/// Specifies a return value type for a method that does not return a value.
/// </summary>
/// <filterpriority>2</filterpriority>
[ComVisible(true)]
[Serializable]
[StructLayout(LayoutKind.Sequential, Size = 1)]
public struct Void
{
}
}
ty这么好的答案先生! –
如果void已经很好地集成到.net中,而不是用作解决方法,它会不会提供更好的性能? –
@AppDeveloper,我认为它不会影响性能,它真的只是控制函数如何编译,以及它们是否返回值。 C#无效函数或VB子只是不返回值,所以用于推送/弹出堆栈值的IL代码只是省略。 – Kratz