Strings

Write a method to reverse a string in C#?
public string Reverse(String str)
{
char[] arr = str.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}

Write a method to reverse the order of the words in a sentence? For example For example for a given string: "This is a pen", convert it to "pen a is This".

public static string WordReversal(string sentence)
{
string[] words = sentence.Split(' ');
Array.Reverse(words);
return string.Join(" ", words);
}
Will the following code compile and run?
string str = null;
Console.WriteLine(str.Length);
The above code will compile, but at runtime System.NullReferenceException will be thrown.
How do you create empty strings in C#?
Using string.empty as shown in the example below.string EmptyString = string.empty;

How do you determine whether a String represents a numeric value?
To determine whether a String represents a numeric value use TryParse method as shown in the example below. If the string contains nonnumeric characters or the numeric value is too large or too small for the particular type you have specified, TryParse returns false and sets the out parameter to zero. Otherwise, it returns true and sets the out parameter to the numeric value of the string.
string str = "One";
int i = 0;
if(int.TryParse(str,out i))
{Console.WriteLine("Yes string contains Integer and it is " + i);
}
else
{
Console.WriteLine("string does not contain Integer");
}