Programming for Perverts
Today I was looking at a Sun Certified Java Programmer example test (quite an old one - url no longer valid). There were some quite curious questions. I have taken out and modified questions that apply to C# (unless otherwise noted) and left out Java specific ones. Try to guess the compilation result/output! Here they are in C# version:
int i = 1;
i <<= 31;
i >>= 31;
Console.WriteLine(Double.NaN == Double.NaN);
double zero = 0;
Console.WriteLine(Double.NaN == 3 / zero);
int i = 10;
int j = 10;
bool b = false;
if (b = 10 == 10)
4. This one behaves differently in Java and C#
System.out.println(-0.0 == +0.0);
System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
Console.WriteLine(-0.0 == +0.0);
Console.WriteLine(Math.Min(-0.0, +0.0) == Math.Max(0.0, +0.0));
int i = 0;
Console.WriteLine(i++ + ++i);
Console.WriteLine(i++ + i++);
Console.WriteLine(Double.PositiveInfinity + Double.NegativeInfinity);
Console.WriteLine(Double.PositiveInfinity == Double.PositiveInfinity);
Check the full article for the actual output!
.NET and SQL Server Adventures
While preparing the last set of upgrades for the no-blog I stumbled upon some strange issues with different technologies. I reasoned that I might help some of you or some poor googling soul by posting about them here...
What Is New in C# 3.0 - Part 8 (LINQ to SQL)
This is the end, beautiful friend, the end. The end of (your) laughter and (my) soft lies. The end of nights we tried to code. The final part of the series. Because this is a series about the new things in the LANGUAGE C# 3.0 and not in Visual Studio 2008 or .NET Framework 3.5 it will end here. Actually this article is also out of scope but it is needed to better demonstrate how the features work in practice.
What Is New in C# 3.0 - Part 7 (LINQ Syntax)
Here is the cherry of the cake, the reason for all the new features in C# 3.0, the purpose of human evolution and the reason Google created the Universe in the first place. LINQ (Language Integrated Query) is a set of C# language features for manipulating data. Long time ago Anders (Hallowed be his name) reasoned that as more and more applications interact with different data stores and manipulate large sets of data it would be really cool to make data manipulation a first class language feature. The most popular way for applications to interact with data are the databases but data comes in many more forms for example XML documents. So the first problem was to define what data is.
What Is New in C# 3.0 - Part 6 (Expression Trees)
After a long delay I am proud (well not really) to present part 6 of the “What Is New in C# 3.0” series. This is arguably the most difficult part of all but you only need to fully understand how expression trees work if you are going to develop LINQ data providers or similar frameworks. I personally am nowhere near to fully understanding how expression trees work but learning the principles they rely on will help you and me use them more effectively.