Thursday, June 19, 2008

Difference among Int32.Parse(), Convert.ToInt32(), and Int32.TryParse()

Have you ever considered between the methods which are used convert to integer? If yes or no, please continue to read. When you write code, probably you use convert process between types. Especially from string type to integer type. NET Framework 1.x supports two methods for converting. One of them is Int32.Parse and another is Convert.ToInt32. And also in .NET framework 2.0, Int32.TryParse is available in c#. Ok let's begin to explain what are differences between them.

First of all. we define the variables to be used following examples.

string s1 = "123";
string s2 = "123.45";
string s3 = null;
string s4 = "123456789123456789123456789123456789123456789";

int result;
bool success;


Int32.Parse(string s)
When s is null, ArgumentNullException is throwed, if s is not integer value, FormatException is throwed. If s represents number less than MinValue or grater than MaxValue, OverFlowExceptin is throwed.

result = Int32.Parse(s1); //output --> 123
result = Int32.Parse(s2); //
output --> FormatException
result = Int32.Parse(s3); //
output --> ArgumentNullException
result = Int32.Parse(s4); //
output --> OverflowException

Convert.ToInt32(string s)
When s is null, zero is returned, if s is not integer value, FormatException is throwed. If s represents number less than MinValue or grater than MaxValue, OverFlowExceptin is throwed.

result = Convert.ToInt32(s1); //output --> 123
result = Convert.ToInt32(s2); //
output --> FormatException
result = Convert.ToInt32(s3); //
output --> 0
result = Convert.ToInt32(s4); //
output --> OverflowException

Int32.TryParse(string, out int)
When s is null or not integer value, zero is returned.

success = Int32.TryParse(s1, out result); //output --> true; result => 123
success = Int32.TryParse(s2, out result); //
output --> false; result => 0
success = Int32.TryParse(s3, out result); //
output --> false; result => 0
success = Int32.TryParse(s4, out result); //
output --> false; result => 0

As a result, Int32.TryParse is most usefull and better. it reduces the risk of converting to integer during runtime.

Thursday, June 12, 2008

10 Things Make Developers to be Succesfull

1.Clarifying user requirements

As you spend more time developing an application, you can sometimes predict some of the requests of your customers. Don’t take this for granted and assume you know more than your users do. When you receive the requirements, spend some time with them and review their specification to confirm you are on the same page. Not doing so can end up costing you time as you rework the application later on.

2.Collaborating

Call it brainstorming, call it peer code review, call it whatever you want — but just make sure you collaborate with those around you. Bouncing ideas off others will help you identify any holes in your potential solution and might even help you develop a solution better than your original design.

3.Version control

Anybody who has ever had his or her code stepped on or deleted knows the value of a good version control system. It doesn’t matter if its CVS, ClearCase, or even Visual Source Safe. Get it, learn it, and use it. You don’t want all your hard work to be blown away with a few mistaken keystrokes.

4. Basic system testing

Most developers don’t like to test. Or maybe I should say most developers hate testing. But it’s crucial for you to do your own testing before you release it to anybody else. Nothing will get your testing group upset and knocking on your door quicker than receiving code that doesn’t perform the basics. Make sure entry screens allow input, check that you can’t enter a letter where only numbers are allowed, verify that reports actually print information and that columns add up — the basic stuff.

5. Usability

Early in my career, I designed a screen for a group of data entry users. I thought my design was so slick. The system had all the bells and whistles they needed and then some. I was just about ready to install it when it was pointed out to me that the users almost never used a mouse. My design had added some buttons to the screen and had them lifting their hands from the keyboard over and over. Not efficient for them and very humbling for me. Spend some time to learn about the types of usability issues your customers may have and everybody will be happier.

6. System performance

In this era of instant gratification, it’s hard to satisfy end users. When they click on a button, they expect that the system will immediately respond. Or they may have the misconception that overnight processes really should take only an hour or two. When developing your application, ensure that you understand what type of response the users expect and require.

7. Comments in your code

Comments are the bane of many developers’ existence. We want to spend our time writing code not writing about code. But most of us have been tasked at some point with going in and maintaining somebody else’s work. If you’re like me, you may have sometimes found it so confusing that your first reaction was to rip it all out and start over. My experiences have taught me that even by adding some very basic commenting around sections of code and trying to use descriptive variable names and the like, you can have a significant positive impact on the next person who has to maintain your legacy.

8. Logging

When you’re developing applications (especially those without any type of user interface), make sure you build some helpful logging solutions into the code. There are few worse things for a developer to do than to try to debug an application with little visibility into what is going on when it is running.

It doesn’t have to be overly complex. Maybe just writing out some of the values of your variables or counters at certain places in the code or when it hits certain subroutines. You can set it up so it logs only when a particular environmental condition exists (maybe a specific text file exists in a directory). Trapping anything that is going to help you track down and resolve issues quickly is what you’re going for here.

9. Keeping your skills up to date

Still coding in something a few years old? Many people work for companies run by legacy applications that are past their prime. But that doesn’t mean you should ignore what’s going on in the world around you. A lot of the new technologies out there can be integrated and could provide a boost to you and your company. Take some time to try to understand them a bit, and who knows when you can use it to your advantage.

10. Taking pride in your work

One thing I always thought about and tried to pass along to my teams was the concept of having pride and ownership in the applications we were responsible for. I never wanted to hear that my applications weren’t working at their peak capabilities or that users were happy. And if we did hear about a problem, we would go out of our way to do everything we could to rectify the situation immediately.

It doesn’t matter if you are a head-down developer in a large organization, a systems designer, or a single jack-of-all-trades for your own company. Taking some of these ideas into consideration will not only help you produce a better end product but it will also allow you continue to evolve yourself and your career to the next level.

Tuesday, June 10, 2008

LINQ Pad


LINQ stands for .NET Language Integrated Query which helps developers to query ant data soruce. You can filter any data source such as ArrayList, Collections, DataSet or Xml File etc. If you know T-SQL, it's easy for you to use LINQ. And you understand what i mean.

Speaking LINQ, i came accross the tool which is used to query with LINQ. LINQPad. LINQPad has lots of sample about LINQ. If you want to learn LINQ, it's for you. And LINQPad is more than just a LINQ query tool: it's a code snippet IDE. Instantly execute any C# 3 or VB 9 expression or statement block.

LinqPad Homepage
LinqPad Download