Things you probably didn’t know about C# – Part 2
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
Warning: file_get_contents(http://feeds.delicious.com/v2/json/urlinfo/data?url=http%3A%2F%2Fwww.devtheweb.net%2Fblog%2F2010%2F03%2F04%2Fthings-you-probably-didnt-know-about-csharp-part-2%2F) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
After a post about Things you probably didn’t know about C#, here’s a new post from the series:
1. If you want to exit you app without calling any finalizers or finally blocks use:
Environment.FailFast();
2. Instead of
sting filePath = directoryPath + “\\” + filename;
you can use:
sting filePath = System.IO.Path.Combine(directoryPath, filename);
3. Forget about “\r\n” for new line, you can use Environment.NewLine instead. It’s better because it’s system independent
4. You can create a typed reference from a variable:
int i = 100;
TypedReference typeRef = __makeref(i);
5. From the example above, you can extract the original type:
Type type = __reftype(typeRef);
6. You can extract the value from TypedReference:
int j = __refvalue(typeRef, int);
7. You can use the ‘@’ character in the beginning of variable names. It’s suitable to be used for vars:
var @obj = new object();
8. If you want the garbage collector to collect some object while it can be accessed by the application, you can use the System.WeakReference class, you can read more about it HERE.
P.S. I’ve test all the examples above under .NET Frawork 3.5.

