csharpspec | C # language specification
kandi X-RAY | csharpspec Summary
kandi X-RAY | csharpspec Summary
C# language specification
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of csharpspec
csharpspec Key Features
csharpspec Examples and Code Snippets
Community Discussions
Trending Discussions on csharpspec
QUESTION
When using reflection Type.IsPrimitive
on a void
type returns false.Coming from a C++ background this was surprising.
Looking at the C# 6.0 spec (Page 82) does not mention the void
type, which could mean that it isn't categorized as a type altogether.
Is there anything in the language spec or otherwise that categorizes void
as something else. Or any other discussion or such which mentions the reason behind this?
ANSWER
Answered 2017-Mar-17 at 12:33From reading the C# Specification, there is no mention of a type void
. It is written about as a return type
. In the table of contents, it is not categorised under reference or value types. It is mentioned as a keyword.
The section on the typeof
function says:
The third form of typeof-expression consists of a typeof keyword followed by a parenthesized void keyword. The result of an expression of this form is the System.Type object that represents the absence of a type. The type object returned by typeof(void) is distinct from the type object returned for any type. This special type object is useful in class libraries that allow reflection onto methods in the language, where those methods wish to have a way to represent the return type of any method, including void methods, with an instance of System.Type.
Which to me indicates that void
has an associated type but is only used in the case where you want reflection to give you something tangible because of the type system. Otherwise void
is just a keyword.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install csharpspec
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page