Proper Linq where clauses

EDIT: LINQ to Objects doesn’t behave how I’d expected it to. You may well be interested in the blog post I’ve just written about this… They’re different in terms of what will be called – the first is equivalent to: wheras the latter is equivalent to: Now what difference that actually makes depends on the implementation of Where being called. If … Read more

How does the “Using” statement translate from C# to VB?

Using has virtually the same syntax in VB as C#, assuming you’re using .NET 2.0 or later (which implies the VB.NET v8 compiler or later). Basically, just remove the braces and add a “End Using” You can get the full documentation here http://msdn.microsoft.com/en-us/library/htd05whh(VS.80).aspx EDIT If you’re using VS2003 or earlier you’ll need the below code. … Read more

Unity3d restart current scene

You must ask the scene manager to load the scene using LoadScene You were just retrieving the build index of the current scene. Also, about yourcompilling error, you have forgotten the semi-colon at the end of the line 😉

What is and how to fix System.TypeInitializationException error?

Whenever a TypeInitializationException is thrown, check all initialization logic of the type you are referring to for the first time in the statement where the exception is thrown – in your case: Logger. Initialization logic includes: the type’s static constructor (which – if I didn’t miss it – you do not have for Logger) and field initialization. Field initialization is pretty … Read more

Incorrect string value: ‘\xEF\xBF\xBD’ for column

\xEF\xBF\xBD is the UTF-8 encoding for the unicode character U+FFFD. This is a special character, also known as the “Replacement character”. A quote from the wikipedia page about the special unicode characters: The replacement character � (often a black diamond with a white question mark) is a symbol found in the Unicode standard at codepoint U+FFFD in the … Read more

Associating enums with strings in C#

I like to use properties in a class instead of methods, since they look more enum-like. Here’s an example for a Logger: Pass in type-safe string values as a parameter: Usage:

Does anyone still use [goto] in C# and if so why?

There are some (rare) cases where goto can actually improve readability. In fact, the documentation you linked to lists two examples: A common use of goto is to transfer control to a specific switch-case label or the default label in a switch statement. The goto statement is also useful to get out of deeply nested … Read more

Why not use Html.EditorForModel()

Ok I just discovered about the EditorForModel in MVC and I want to know when I should use this instead of an EditorFor on each of my property? And why does when I add a strongly typed view it does not use this and build an EditorFor on every property? I’m late on this… but thanks for the info!