We all know that the runtime can detect the actual type of a System.Object
instance. The primitive data types provided by the runtime are compatible with one another for casting (assuming that we do not truncate the values). So if I have an int
, it can be cast to long
or ulong
. All that is fine. Watch this:-
interface IAppDataTypeBase
{
// Other methods
GetValue();
}
Since IAppDataTypeBase represents the mother of all types of data in my application, I have made GetValue to return the value as object (I could have used generics, that is for another day!).
More ...
Let us take a look at the following piece of code:-
public void Operate(IList iList2)
{
iList2 = new List();
iList2.Add(1);
iList2.Add(2);
iList2.Add(3);
}
public static void Main()
{
IList iList= new List();
iList.Add(10);
Operate(iList);
Console.WriteLine(iList[0].ToString());
}
Be thinking about what would the above program print to the console ? And that is what we are going to talk about in this post β simple but subtle.
More ...
Extension Methods is an excellent feature in C# 3.0. It is a mechanism by which new methods can be exposed from an existing type (interface or class) without directly adding the method to the type. Why do we need extension methods anyway ? Ok, that is the big story of lamba and LINQ. But from a conceptual standpoint, the extension methods establish a mechanism to extend the public interface of a type. The compiler is smart enough to make the method a part of the public interface of the type. Yeah, that is what it does, and the intellisense is very cool in making us believe that. It is cleaner and easier (for the library developers and for us programmers even) to add extra functionality (methods) not provided in the type. That is the intent. And we know that was exercised extravagantly in LINQ. The IEnumerable was extended with a whole lot set of methods to aid the LINQ design. Remember the Where
, Select
etc methods on IEnumerable
.
More ...
Guess the output of the following program:-
class SomeClass : IDisposable
{
public SomeClass()
{
Trace.WriteLine("SomeClass - Attempting instance creation");
throw new Exception("Ohh !!! Not Now");
}
public void Dispose()
{
Trace.WriteLine("SomeClass::Dispose");
}
~SomeClass()
{
Trace.WriteLine("SomeClass::Finalizer");
}
}
int Main(string args[]){
try{
SomeClass sc = new SomeClass();
}
catch(Exception ex){
Trace.WriteLine("Main - {0}", ex.Message);
}
}
This will be the output of the program:-
More ...
When I started developing my module, I had an interface IParamCountBasedAlgo declared as a nested type in a class AlgorithmOneExecutor, declared as follows:-
namespace DataStructuresAndAlgo
{
partial class AlgorithmOneExecutor
{
private interface IParamCountBasedAlgo
{
void Validate();
void Execute();
}
}
}
I did some cool stuff here with google. I wrote my first βHello Worldβ sort of google gadget. It claims no rewards but just was fun. Since I am a novice in html and javascript sort of things, this gadget is pretty simple.
Use the following URL to enjoy the gadgets.:
I could not stop writing this post after I read this article by Herb Sutter. The article is just a casual technical discussion but very encouraging that a person requires at the right time β the time when he is a student. Even after several years after my college, I have been trying to keep myself a student and I got a right encouragement to join the Concurrency revolution. Thanks to Herb Sutter. More ...
I am very much fond of tools, updates and stuff. So I keep updating my softwares and hear/learn about new tools etc. I am excited about the new spaces - Live Spaces. Looks much better than before. I thought I would write something about the new spaces. Please spaces guys, make the arranging the boxes on the home page a bit easier and intelligent. That is a feature request. Otherwise the default skin/theme is cool and professional. Old themes are still old and not much appealing. Anyway, i write the post just to say i love it. More ...
I was writing a generic method with enum
as the Constraint, and the compiler spat a few errors that did not directly convey me that enum
s cannot used as generic constraints. I learnt the following from my investigation:
Following is an excerpt from the C# language specification for generic constraints
A class-type constraint must satisfy the following rules:
The type must be a class type.
The type must not be sealed.
The type must not be one of the following types: System.Array
, System.Delegate
, System.Enum
, or System.ValueType
.
This was a pretty interesting discussion about method overloading in the managed world. As the discussion says that the overloading is a matter of taste. It seems that the method overloading in the managed world, indeed, is a matter of taste. Sad BUT True !!! But on the contrary, it must have been a [strict] rule. Overloading might be exhibited differently by each language in the unmanaged world. But as far as .NET goes, it must have been made a standard specification. Pardon me, if there is one. More ...