Convert Enum to String
Which is the preferred way to convert an Enum to a String in .NET 3.5? Enum.GetName Enum.Format ToString Why should I prefer one of these over the others? Does one perform better? 15 Answers 15
Which is the preferred way to convert an Enum to a String in .NET 3.5? Enum.GetName Enum.Format ToString Why should I prefer one of these over the others? Does one perform better? 15 Answers 15
What is the recommended way of formatting TimeSpan objects into a string with a custom format? 20 Answers 20
I have some code like this: If key.Equals(“search”, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I don’t care about the case. Should I use OrdinalIgnoreCase, InvariantCultureIgnoreCase, or CurrentCultureIgnoreCase? 5 Answers 5
I would like to compare the contents of a couple of collections in my Equals method. I have a Dictionary and an IList. Is there a built-in method to do this? Edited: I want to compare two Dictionaries and two ILists, so I think what equality means is clear – if the two dictionaries contain … Read more
When I open my solution by double click on solution file in a file manager, Visual Studio 2012 asks me whether I want to save devenv.sln: How can I avoid this annoying thing? (except of opening vs first and than solution – I want just to click a solution file in my file manager). 2 … Read more
Just looking for a short overview of GAC for a layman, not a link please. 8 Answers 8
Consider the below code: public class Class1 { public static int c; ~Class1() { c++; } } public class Class2 { public static void Main() { { var c1=new Class1(); //c1=null; // If this line is not commented out, at the Console.WriteLine call, it prints 1. } GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(Class1.c); // prints 0 Console.Read(); } … Read more
I have used the “select” keyword and extension method to return an IEnumerable<T> with LINQ, but I have a need to return a generic Dictionary<T1, T2> and can’t figure it out. The example I learned this from used something in a form similar to the following: IEnumerable<T> coll = from x in y select new … Read more
I had this code: String[] lineElements; . . . try { using (StreamReader sr = new StreamReader(“TestFile.txt”)) { String line; while ((line = sr.ReadLine()) != null) { lineElements = line.Split(‘,’); . . . but then thought I should maybe go with a List instead. But this code: List<String> listStrLineElements; . . . try { using … Read more
Is there a difference between Server.UrlEncode and HttpUtility.UrlEncode? 6 Answers 6