Greetings Overflowers,
I know in C we can define a struct inline with the variable declaration so that the struct type is specific to this variable. This is instead of defining the type alone then declaring the variable to be of that struct type. Is this possible in C#?
Thank !
C *= A is equivalent to C = C * A. /= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to C = C / A.
The closest thing you can get is a struct . There is a feature in C intended to facilitate a sort of pseudo-inheritance, but it doesn't come close to an actual object-oriented class system.
It allows efficient development without the need to incorporate or switch to C++ or languages with builtin template systems, if desired. Using generics and templates in C can also make programs more type safe, and prevent improper access of memory.
There's no new / delete expression in C. The closest equivalent are the malloc and free functions, if you ignore the constructors/destructors and type safety.
This is not possible in C#, however you can define an instance of an anonymous type like this:
var x = new { SomeField = 1, SomeOtherField = "Two" };
This would effectively be the same, giving you an instance of a type that is specific to that variable and cannot used outside the variable's scope.
Simple answer: No, it is not possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With