Browse by Tags

All Tags » C# 3.0 (RSS)
If you’ve programmed in any managed language in Visual Studio, you’d have definitely seen those nagging red squiggles that appear as you type, telling you just how dumb you are, every time you pause typing. Might not be everyone’s cup...
Posted by Senthil | 3 comment(s)
Filed under: , ,
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 | 1 comment(s)
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 | 2 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 | 1 comment(s)
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 | 5 comment(s)
Filed under: , ,
If you’ve done any multithreading programming at all, you must be aware of the volatile modifier. When a field is marked volatile, it tells 1. the JIT compiler that it can’t hoist the field because it may be modified by multiple threads 2. the CLR that...
Posted by Senthil | 5 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...
I'll bet a hundred bucks that any entry level C++ interview or exam will somehow drift into questions about the pre and post increment operators. It's almost become a canonical, rite of passage sort of thing. Now using the operators is one thing...
Posted by Senthil | with no comments
Implementing IEnumerable<T> can turn out to be tricky in certain cases. Consider the following code snippet namespace Test { class Program { static void Main( string [] args) { Consume( new List < string >() { "a" , "b"...
Posted by Senthil | with no comments
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>...
There is a description of the bug here . The following piece of code demonstrates the bug. class Program { interface I { int X { get; set; } } struct S : I { public int X { get; set; } } static void Main(string[] args) { Func<S>(); } static void...
Posted by Senthil | 2 comment(s)
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...