Friday, November 26, 2010

Difference between int.Parse and Convert.ToInt32

I know this post sound basic to most of people but still lots of people does not know this. So I decided to post a blog post for this. Both int.Parse and Convert.ToInt32 are used to convert string into the integer but Only difference between them is to Convert.ToInt32 handle null and returns ‘0’ as output and int.parse is not going to handle NULL and will give a Argument Null Exception. Here is the example for that both are almost same except handling null.


          string convertToInt = "12";
string nullString = null;
string maxValue = "32222222222222222222222222222222222";
string formatException = "12.32";

int parseResult;

// It will perfectly convert interger
parseResult= int.Parse(convertToInt);

// It will raise Argument Null Exception
parseResult= int.Parse(nullString);

//It willl raise Over Flow Exception
parseResult= int.Parse(maxValue);

//It will raise Format Exception
parseResult= int.Parse(formatException);


//For Convert.ToInt32

//It will perfectly convert integer
parseResult= Convert.ToInt32(convertToInt);

//It will ouput as 0 if Null string is there
parseResult= Convert.ToInt32(nullString);

//It will raise Over Flow Exception
parseResult= Convert.ToInt32(maxValue);

//It will raise Format Exception
parseResult= Convert.ToInt32(formatException);

Hope this will help you understand the better but still there is third option available called int.TryParse which can handle all kind of exception and return result as Output Parameter.

Shout it
kick it on DotNetKicks.com
Share:

Microsoft Community Techdays in Ahmedabad on 11th December

Microsoft Community Techdays is a great event organized by Microsoft for Every Quarter. Its going to be there on 11th December in Ahmedabad. I want to be there hope I could as my schedule is so start but you guys can not forgot to register at this event. It’s totally free and It’s great place to meet lots of interesting guys like Pinal Dave,Jacob Sebastian etc.

spot

Here are the schedule for Ahmedabad.

10:15am - 10:30am
Welcome - Pinal Dave

10:30am - 11:15am
SQL Tips and Tricks for .NET Developers by Jacob Sebastian

11:15am - 11:30am
Tea Break

11:30am - 12:15pm
Best Database Practice for SharePoint Server by Pinal Dave

12:15pm - 01:00pm
Self Service Business Intelligence by Rehab

01:00pm - 02:00pm
Lunch

02:00pm - 02:45pm
Managing your future, Managing your time by Vinod Kumar

02:45pm - 03:30pm
Windows Azure News and Introducing Storage Services by Mahesh Devjibhai Dhola

03:30pm - 03:45pm
Tea Break

03:45pm - 04:30pm
Improve Silverlight application with Threads and MEF by Prabhjot Singh Bakshi

04:30pm - 04:45pm
Thank you - Mahesh Devjibhai Dhola

So don’t forgot to be there. Register your seat at : http://www.communitytechdays.com

Shout it
Share:
Friday, October 29, 2010

Difference between Web Service and WCF Service

While taking interviews of .NET developers I often ask this questions. But lots of people don’t know exact difference between this. So, I decided to write a separate blog about this.

Here are the few differences.

  • Web services can be hosted in IIS as well as outside of the IIS. While WCF service can be hosted in IIS, Windows activation service,Self Hosting,WAS and on lots of proctols like Named Pipe,TCP etc.Here lots of people disagree how we can host the web service outside of the IIS but Here is the article for that.http://msdn.microsoft.com/en-us/library/aa529311.aspx.
  • In Web Services Web Service attribute will added  on the top of class. In WCF there will be a Service Contract attributes will be there. Same way Web Method attribute are added in top of method of Web service while in WCF Service Operation Contract will added on the top method.
  • In Web service System.XML.Serialization is supported while in the WCF Service System.RunTime.Serialization is supported.
  • WCF Services can be multithreaded via ServiceBehavior class while web service can not be.
  • WCF Services supports different type of bindings like BasicHttpBinding, WSHttpBinding, WSDualHttpBinding etc.while Web services only used soap or xml for this.
  • Web services are compiled into a class library assembly. A file called the service file is provided that has the extension .asmx and contains an @ WebService directive that identifies the class that contains the code for the service and the assembly in which it is located while in WCF.WCF services can readily be hosted within IIS 5.1 or 6.0, the Windows Process Activation Service (WAS) that is provided as part of IIS 7.0, and within any .NET application. To host a service in IIS 5.1 or 6.0, the service must use HTTP as the communications transport protocol.

Hope this will help you. Happy programming!!!

Technorati Tags: ,,
Shout it
kick it on DotNetKicks.com
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews