.Net
Posts about .Net in general.
Hey there! So recently I was struggling with something for the new job, and was able to figure it out, and thought I'd share it with you, dear readers. I have a generic class I use for parsing data. Inside that class, I ran across the need to create another instance of the generic class to parse more data, but I didn't know the type at compile time. So I have this class: public class MyClass<T> where T: class { public void DoSomething() { } } In the course of DoSomething, I need to create a...
Recently I was trying to use StringBuilder.AppendFormat to build some javascript, and was hit with an exception when trying to do this: sb.AppendFormat("function {0}(args) { return false; }", someVariable); The problem is that you can't have { or } inside an input string for string.Format(). The solution is actually fairly straightforward: sb.AppendFormat("function {0}(args) {{ return false; }}", someVariable); Instead of using "\" as an escape character, you would use { or } (depending on what you...