Browse by Tags

All Tags » C# (RSS)

Can You Spot the Bug? Lethal Combination

I blogged not too long ago about some stuffs that I was pondering … Finally found out how one can get the “ Object of type ‘System.Decimal’ cannot be converted to type ‘System.Int32’ ” error.   Given this code: 1: using System; 2: using System.Data;...
Posted by Jimmy Chandra | 1 comment(s)
Filed under: ,

Musing About Generic Inheritance (Class Person : EntityBase<Person>).. What?

Was strolling around StackOverflow and came to a question #1118232. Where this guy was asking how come you can create a class inheriting from another generic class like so: class Person : EntityBase<Person> { //Whatever here... } He said it’s like...
Posted by Jimmy Chandra | 1 comment(s)
Filed under: , ,

if (you is CSharpDeveloper) Read(this) //Hidden Features of C#

public class CallToAction { abstract class CSharpDeveloper { } class You : CSharpDeveloper { } string ReadTheContentOf(System.Uri url) { return string .Empty; } System.Uri URL = new System.Uri( " http://stackoverflow.com/questions/9033/hidden-features...
Posted by Jimmy Chandra | with no comments
Filed under: ,

Unexpected Method Group Placement

This thing has been around since C# 2.0, but recently, I saw it in unexpected places as a replacement for a Predicate<T> in a parameter. Usually you found it as the right side of an assignment / removal of an event handler such as: //using Method...
Posted by Jimmy Chandra | 2 comment(s)
Filed under: ,

Globalization / Localization Strikes Again

To assume, as they said it, is to make an ass of u (you) and me . And that's exactly what happened recently on one of my side projects. I created a stock quote component that will retrieve stock data in form of a CSV from Yahoo! Finance. Take a look...
Posted by Jimmy Chandra | 1 comment(s)
Filed under: , ,

Back to Basic: C# Using statement, Return and IDisposable

In day to day coding, I found myself using a lot of disposable objects like DbConnection, Font, etc. And so, naturally, putting this code block inside a using statement is common sense. In theory, I know that when you use a using block in your code, your...
Posted by Jimmy Chandra | with no comments
Filed under: , , ,

Back to Basic: Debug.Assert(...)

I wonder how many of us litter our code with this particular line? How do you use them? Do you know what you need to watch out when you do use them? Is it necessary to put this line of code in our code? What is the consequence of putting this line into...
Posted by Jimmy Chandra | 1 comment(s)
Filed under: , ,

Detecting If a Number has a Decimal Fraction

This seems like pretty basic functionality of a number type, but I can't seem to be able to find any built-in function in any of .Net number type that support decimal (decimal, double) or the System.Math class to do this. In any case, if you find...
Posted by Jimmy Chandra | 4 comment(s)
Filed under: ,

On Activator.CreateInstance...

When you use .NET Activator.CreateInstance to create a new object of a certain type, make sure you reference the Project / DLL that contain the type definition or load it manually somehow to an AppDomain . Otherwise your call will fail. Say you have the...
Posted by Jimmy Chandra | with no comments
Filed under: ,

Playing Around with Anonymous Type, Extension Method, LINQ, and Generic

I was reading this particular entry from AlexJ's blog, in which he discussed how to use anonymous type returned from one function in another function. I strongly recommend you read it first before reading any further. Basically, most people would...

Preview of C# version 3.0 features

Wow, C# 2.0 is not officially out of the door, C# 3.0 is already rearing its head :). In this post I'll go through some of the new features of the 3.0 version of C#. Feature 1: Implicitly typed local variables. Variable declaration has become simpler...
Posted by Jimmy Chandra | with no comments
Filed under: , , ,

Neat Partially Partial C# 2.0 Keyword

Partial is great! The new Partial keyword in C# 2.0 is a excellent addition to the language. What does it do? It allows you to create an extension to an existing class (as long as the original class is also marked Partial) without having to mess around...
Posted by Jimmy Chandra | with no comments
Filed under: , ,