Why C# is not allowing non-member functions like C++

See this blog posting: http://blogs.msdn.com/ericlippert/archive/2009/06/22/why-doesn-t-c-implement-top-level-methods.aspx (…) I am asked “why doesn’t C# implement feature X?” all the time. The answer is always the same: because no one ever designed, specified, implemented, tested, documented and shipped that feature. All six of those things are necessary to make a feature happen. All of them cost huge amounts … Read more

Create empty C# event handlers automatically

I saw this on another post and have shamelessly stolen it and used it in much of my code ever since: public delegate void MyClickHandler(object sender, string myValue); public event MyClickHandler Click = delegate {}; // add empty delegate! //Let you do this: public void DoSomething() { Click(this, “foo”); } //Instead of this: public void … Read more

How do I decide whether to use ATL, MFC, Win32 or CLR for a new C++ project?

It depends on your needs. Using the CLR will provide you with the most expressive set of libraries (the entire .NET framework), at the cost of restricting your executable to requiring the .NET framework to be installed at runtime, as well as limiting you to the Windows platform (however, all 4 listed technologies are windows … Read more

How do ValueTypes derive from Object (ReferenceType) and still be ValueTypes?

C# doesn’t allow structs to derive from classes Your statement is incorrect, hence your confusion. C# does allow structs to derive from classes. All structs derive from the same class, System.ValueType, which derives from System.Object. And all enums derive from System.Enum. UPDATE: There has been some confusion in some (now deleted) comments, which warrants clarification. … Read more

Float vs Double Performance

On x86 processors, at least, float and double will each be converted to a 10-byte real by the FPU for processing. The FPU doesn’t have separate processing units for the different floating-point types it supports. The age-old advice that float is faster than double applied 100 years ago when most CPUs didn’t have built-in FPUs … Read more