C # void type- security

I'm just new to C # programming (from C ++)

My question: In C #, each type inherits an Object. Why does 'void' doesn`t? Could this cause some RT / type security problems or is it just semantics / syntax?

(I know that int / char, etc. uses the base type and boxing / unpacking - my question is specific to void)

thanks

+5
source share
5 answers

In C #, voidis a keyword that is used in two contexts:

  • In the context of method signatures, voidindicates the absence of a return type; it does not belong to the "void" type, which can inherit from object.

    ( . System.Void, void System.Void .)

  • void* , @Colin Mackay, object, .

+11

++, # void , .

# void . ++, , void "" .

, #.

: , , void System.Void. System.Void void. , , . System.Void, , , , ( System.Void, ).

# void
++ void keyword

+1

. . , #, , void, , , . - . - , , Object.

0

Void - , , void, . System.Void struct, , -. , IL, , void, pop, .

EDIT: , . System.Void, , , System.Void #. :

typeof(object).IsAssignableFrom(typeof(void))
typeof(System.ValueType).IsAssignableFrom(typeof(void))

true, void System.ValueType(.. struct)

0

All Articles