Friday 7 June 2013

How to find Column Name and it's Data Type in Sql Server

Following will show you the column list with their datatype of a table in SQL Server.

select col.name as 'ColumName',typ.name as 'DataType' from sys.columns col left join sys.types typ
on col.system_type_id=typ.system_type_id  where object_id=object_id('login')

That will show you the result as below:

Tuesday 28 May 2013

What are Generics in C#?

Generics is the implementation of parametric polymorphism. Using parametric polymorphism, a method or data type can be written generically so that it can deal equally well with objects of various types. It is a way to make a language more expressible, while still maintaining full static type-safety.




Why use generics?

There are mainly two reasons to use generics. These are:
  • Performance – Collections that store objects use Boxing and Unboxing on data types. This uses a significant amount of overhead, which can give a performance hit. By using generics instead, this performance hit is removed.
  • Type safety – There is no strong type information at compile time as to what is stored in the collection.

Wednesday 22 May 2013

How to make the text or word blink?

You can use <Blink></Blink> tag in HTML to make the word or text blink but in is not supported in all the browser.

If you want the blink to work, you will have to write some javascript code to accomplish that by turning on and off the visibility of the element with setInterval.

	

And then the word to be blinked should be as follow:
Hi, I am blinking
Hi, I am blinking

Sunday 14 April 2013

How Compilation in .NET works.?

Compilation in .Net

What is Common Language Runtime (CLR).?

  • CLR works like a virtual machine in executing all languages. 
  • All .NET languages must obey the rules and standards imposed by CLR. Examples: 
    • Object declaration, creation and use
    • Data types,language libraries
    • Error and exception handling
    • Interactive Development Environment (IDE)
  • Development
  • Deployment
  • CLS is a set of specifications that language and library designers need to follow 
    • This will ensure interoperability between languages

Friday 12 April 2013

C# Evolution

I summarized all the key features into a C# Evolution Matrix for your reference as below diagram shows:

Tuesday 9 April 2013

Getting a User’s Time from Twitter API in C#

<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
  <status>
    <created_at>Tue Apr 09 10:08:15 +0000 2013</created_at>
    <id>1016846548</id>
    <text>Hi &quot;everybody&quot; #greetings</text>
    <source>web</source>
    <truncated>true</truncated>
    <in_reply_to_status_id></in_reply_to_status_id>
    <in_reply_to_user_id></in_reply_to_user_id>
    <favorited>false</favorited>
    <user>
      <id>2566935</id>
      <name>Abc Xyz</name>
      <screen_name>Abc</screen_name>
      <location></location>
      <description></description>
      <profile_image_url>http://.../normal.jpg</profile_image_url>
      <url>https://www.blogger.com/blogger</url>
      <protected>false</protected>
      <followers_count>42</followers_count>
    </user>
  </status>
  <status>
    ...
  </status>
</statuses>

Extracting the Data

XDocument document = XDocument.Parse(response, LoadOptions.None);

var query = from e in document.Root.Descendants("status")

            select new UserStatus
            {
                UserName = e.Element("user").Element("name").Value,
                ProfileImage = e.Element("user").Element("profile_image_url").Value,
                Status = HttpUtility.HtmlDecode(e.Element("text").Value),
                StatusDate = (e.Element("created_at").Value.ParseDateTime())
            };

Few things to note about the above code:

1. HttpUtility.HtmlDecode is being used in order to get a readable text. The response contained text like “Testing "posts" #devacademy3” and this method (in System.Web) converts it to “Testing “posts” #devacademy3”.

2. The ParseDateTime() method on the element’s value is an extension method I created in order to parse a DateTime from the special string representation of the time the status was posted: Sat Nov 15 10:08:15 +0000 2008 This method looks like:

public static class StringExtensions
{
    public static DateTime ParseDateTime(this string date)
    {
        string dayOfWeek = date.Substring(0, 3).Trim();
        string month = date.Substring(4, 3).Trim();
        string dayInMonth = date.Substring(8, 2).Trim();
        string time = date.Substring(11, 9).Trim();
        string offset = date.Substring(20, 5).Trim();
        string year = date.Substring(25, 5).Trim();
        string dateTime = string.Format("{0}-{1}-{2} {3}", dayInMonth, month, year, time);
        DateTime ret = DateTime.Parse(dateTime);
        return ret;
    }
}