Some facts about Null in .NET

As I am tweeting around the facts on Nulls for last couple of days, I thought of writing a blog on that as many of you have already requested me on this regard. This post is basically dealing with Nulls and will go through only with basic C# stuffs, so for geeks, it is not recommended and you might end up knowing a little or almost nothing. So if you just here for time pass, then I refer to read on.

Considering the fact Nulls appear on any objects, we have mainly two categories of programmable storage in .NET.

  1. Nullables (generally mutable with exceptions like strings)
  2. Value Types / struct (generally immutable)
Nullables are types that either user defined or in framework in which one of its value can be null. .NET treats null specially. Say for instance :

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Concept Overide vs Method Hiding in terms of C#

Overriding is one of the most interesting topic that many software professionals are dealing with quite regularly. Most of the applications we write in .NET or other languages somehow uses overriding. While you write your class, one of the most important thing that you need to consider is overriding ToString() to ensure that your class does not produce the “Name of the class” rather you produce something useful on your context. Method hiding is another concept similar to Overriding but is actually different in many respect. But I saw many people does have a little confusion among these two concepts and does not know when to use what. Here is some sample which would help you deal with these concepts easy.

Overriding

Overriding means redefining an existing method that comes inherited from parent class. Say for instance, you have defined a class Animal. Animal can move and eat. So let’s define the class :


public class Animal
    {
        public virtual void Walk()
        {
            Console.WriteLine("Animal is now Walking");
        }
        public void Eat()
        {
            Console.WriteLine("Animal eats for living.");
        }
    }


So this is quite a simple class that provides two methods. The first one is Walk which prints a message, and another is Eat, which again prints another message. Now notice, I have made the Walk method of Animal Virtual. Virtual means, the method will be bound at runtime, hence no compile time binding will be produced and runtime object will take over compile time bindings.

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Working With Prism 4.0 (Hello World Sample with MVVM)

Modularity is one of the primary concern when working with a big projects. Most of us think of how we can implement our application that could be reusable across more than one applications. Patterns and Practices Team puts forward the notion of modularity with the help of Unity and Prism which most importantly focus on WPF and Silverlight applications. Being a WPF developer, it would be nice to take this apart and explain you a bit of how you can implement your application using Prism.

Before you begin, I must tell you, this is the most basic article that guides you step by step how you can write your first Prism based application and what are the advantages of building such kind of application. I will take this further in my next posts to make more concrete samples. So if you know the basics of how you can work with Prism, I would recommend you to read my next posts.

Also I assume you have some knowledge of Unity, WPF and MVVM to get you through with Prism.

Where do I find Prism? 

Prism is a framework introduced by Patterns and Practices Team which is available from here. After you install your bits, you will get a folder named Prism on your local drive. After you are done, lets start coding.

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Playing with Reflection and Async

Hi Guys,

Task Asynchronous Pattern as you already know from my article, is one of the major change of next generation .NET applications. As this is already discussed in detail in the article, I will not repeat the same again here in this post. If you don't know what is it, please go ahead and read the article. In this post, I will try to use reflection to invoke our own async method. 
So to start, let us take a look at one of the simplest Async method. 
static void Main(string[] args)
{
    Program p = new Program();

    Task t = p.TryCallAsync(10000);
    t.Wait();

    Console.ReadLine();
}

public async Task TryCallAsync(int delay)
{
    Console.WriteLine("TaskEx.Delay is called : will wait for {0} milliseconds", delay);

    await TaskEx.Delay(delay);

    Console.WriteLine("Finished execution Return to the caller");
}

In this code I have just put a delay of 10 seconds. Now after the execution is finished, another message will be printed on the screen.

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Internals of Array

Arrays are most important part of your program. Almost most of the collection that you work with in .NET framework is internally maintains Array. Say for instance, if you take the List it actually internally represents T[], while Dictionary is actually an array of structure KeyValuePair internally. Hence, array forms a very important part of your program. 

Few days back while browsing over internet when I found an article written one of my buddy Dhananjay Kumar here, I thought how could I forget this important section of C# language, hence in this post, I will cover some of the important things that you need to remember while you use arrays in .NET.


Arrays Vs IEnumerables


Well, when working with Collections, the first thing that will come in your mind is the IEnumerables. Well, IEnumerable is the generic implementation of any iterators. In .NET every array internally implements an IEnuerable. You may think IEnumerable as a iterable sequence, which could be applied to anything that is iterable while array on the other hand has a fixed set of values contiguously allocated. By the way, each arrays actually implements an IEnumerable internally, so eventually in .NET every array is by default an IEnumerable.


Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

.NET Tips – Links on ASP.NET C# MVC Visual Studio Tips


Daily .NET Tips is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.  In this post I am quickly listing down all the tips which are posted over the month May 2011.
To get regular updates visit http://dailydotnettips.com and follow @dailydotnettips at Twitter
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Author's new book

Abhishek authored one of the best selling book of .NET. It covers ASP.NET, WPF, Windows 8, Threading, Memory Management, Internals, Visual Studio, HTML5, JQuery and many more...
Grab it now !!!