Friday 21 November 2014

Some common differences

Difference between Concatenation and placeholder Syntax
using System;
class UserInteractive
{
public static void Main()
{
string name;
Console.WriteLine("What’s Your Name? ");
Console.Write ("Enter Your Name: ");
name=Console.ReadLine();
Console.WriteLine("Hello! "+name+” nice to meet you ”+name”.”);        //Concatenation
Console.WriteLine(“Hello! {0} nice to meet you {1}.”,name,name);  //placeholder
// placeholder are most preferable way.
}
}
//===========================================================================================


Difference between Parse and TryParse
If the no. is in string format you have two option parse and try parse
Parse method throw an exception, if it cannot parse the value.
Whereas TryParse() return a bool indication whether it succeeded or failed.
Use parse() if you are sure the value use valid other wise use try parse.
using System;
//use of parse
class ParseTesting
{
public static void Main()
{
string strNumber="100";
int i=int.Parse(strNumber);
Console.WriteLine(i);
}
}
//===================================================//
using System;
//use of try parse
class TryparseTesting
{
public static void Main()
{
string strNumber="100TG";
int Result;
bool IsConversionSucessful= int.TryParse(strNumber, out Result);
if(IsConversionSucessful)
{
Console.WriteLine(Result);
}
else
{
Console.WriteLine("Please Enter a valid number");
}
}
}
//===========================================================================================

Difference between | and || or & and &&
If we use | or & it always check both the condition of statements whether it satisfies it or not it consume too much compiling time.
Other hand if we use || or && if left hand condition of statements satisfy them they don’t go to the right hand side it saves the compiling time.