Browse by Tags

All Tags » software » C# 3.0 (RSS)
Consider this piece of C++ code. 1: using namespace std; 2: 3: class C 4: { 5: public : 6: C() 7: { 8: cout << "Constructed" ; 9: } 10: ~C() 11: { 12: cout << "Destructed" ; 13: } 14: }; 15: 16: void SomeFunc() 17: { 18...
This piece of code results in a warning. 1: class Test 2: { 3: public static void Main() 4: { 5: object obj = "Senthil" ; 6: string myName = "Senthil" ; 7: Console.WriteLine(obj == myName); 8: } 9: } The compiler says “warning CS0252...
Posted by Senthil | with no comments
Filed under: , ,
Mixing SetEnvironmentVariable and getenv is asking for trouble, as we recently found to our dismay (and exasperation!). It took some serious debugging to figure out the actual problem – let’s see if you can figure it out. Here’s some C++/CLI code that...
The previous post discussed having anonymous methods as event handlers and ended with a question – why doesn’t unsubscription work while subscription works out alright? Vivek got the answer spot on – the way the C# compiler handles and translates anonymous...
Posted by Senthil | 2 comment(s)
Filed under: , , ,
The syntactic sugar offered by anonymous methods makes them great candidates for writing event handlers; together with smart type inference, they reduce the amount of code written by an order of magnitude. And that’s without considering the power offered...
Posted by Senthil | 3 comment(s)
Filed under: , , ,
You're writing this really cool and innovative class to calculate the first hundred thousand natural numbers. You think about the API, and you realize that returning an array of the numbers a) might take a long time to complete, and b) is going to...
Posted by Senthil | with no comments
Filed under: , ,
My colleague Soundar discovered this rather interesting behavior. 1: class Test 2: { 3: public static void Main() 4: { 5: Test test = null ; 6: 7: Console.WriteLine(" {0} ", test); 8: Console.WriteLine(" {0} ", null ); 9: } 10: } If...
Posted by Senthil | 4 comment(s)
Filed under: , ,
Take a look at the following short snippet of code. 1: using System; 2: 3: struct S 4: { 5: public int X; 6: } 7: 8: class C 9: { 10: /* More code here */ 11: } 12: 13: class Test 14: { 15: public static void Main() 16: { 17: C c = new C(); 18: c.S.X...
Posted by Senthil | 1 comment(s)
Filed under: , ,
Ever since I happened to stumble upon this book on Data Mining, I've been hooked. So much so that I've been brushing up on statistics and probability distributions just to follow along the book. I'm currently reading the chapter on classification...
Tee is a cool function that "clones" enumerators whatever their current state is - it basically allows you to branch off an enumerator into as many enumerators as you want, all independent of each other. You can do something like List<int>...
Local variable type inferencing is a new feature in C# 3.5 - a very "handy" one, in that it saves a lot of typing. Basically, it lets you do var dict = new Dictionary<string, List<int, Dictionary<int, string>>>(); instead of...