Generic Type Conversion snippet for C# and VB.NET

Here you can find a generic Type conversion snippet for C# and VB.NET.

Sample C#

public static T GenericConvert<T, X>(X value) where X : IConvertible
{
	return (T)Convert.ChangeType(value, typeof(T));
}

Sample VB.NET

Public Shared Function GenericConvert(Of T, X As IConvertible)(value As X) As T
	Return DirectCast(Convert.ChangeType(value, GetType(T)), T)
End Function

How to reload a ViewController in IOS using Objective-C

To reload a UITableViewController in IOS using Objective-C you can simply use the reloadData method of the ViewController.

//MyTablViewController is a UITableViewController
[MyTableViewController.tableView reloadData] 

How to format a float to 2 decimal places in Objective-C

To format a float to 2 decimal places in Objective-C you can use the following snippet.

Sample Objective-C

NSString* formattedVariable = [NSString stringWithFormat:@"%.02f", myFloatVariable];

How to check if an array contains a value in Javascript

To check if an array contains a value in Javascript you can use the snippet below.

Sample Javascript

Array.prototype.inArray = function (inputValue) {
	var counter;
	for (counter=0; counter < this.length; counter++) {
		if (this[counter] === inputValue) {
			return true;
		}
	}
	return false;
};

How to create a folder in C# and VB.NET

To create a folder in C# and VB.NET you can use the following snippet.

Sample C#

try
{
	const string path = @"C:\Users\Codesnippets\Desktop\Testfolder\Test1\Test2";
	Directory.CreateDirectory(path);
}
catch (Exception ex)
{
	//handle the exception your way
}

Sample VB.NET

Try
	Const  path As String = "C:\Users\Codesnippets\Desktop\Testfolder\Test1\Test2"
	Directory.CreateDirectory(path)
Catch ex As Exception
        'handle the exception your way
End Try