3 ms·
does the language allow something like the following?: yes, exactly. The problem is you see stuff like this: var obj = new SomeType(); obj = GetSomeType(
by dbattaglia 15y ago
does the language allow something like the following?:
yes, exactly. The problem is you see stuff like this:
var obj = new SomeType();
obj = GetSomeType();
Basically creating 2 objects, the first of which is immediately garbage since it no longer has any roots. Anyone who understands pointers/references and memory allocation should understand that "new" is actually creating a new live object on the heap, rather than just initializing a pointer to null (or a stack-based value type to zero).
These days C# is actually a decent language to code in, it has a nice functional aspect to it with linq/lambdas, and you can still go down to C style pointers/"unsafe" code if necessary (with lots of restrictions of course). It's really the Microsoft dependency that kills it more than anything else.
- eru 15y agovar obj = new SomeType(); obj = GetSomeType(); You could almost be tempted to write an automatic converter to var obj = GetSomeType(); but you can't in general, because you don't know whether `new SomeType()' doesn't have side-effects. But if it has some that are relied on, that's probably a bug. I know that there's a free .net runtime called Mono. What about the compiler side of free C#?