What is the best datatype for money in C# and VB.NET

The best Datatype for money in C# and VB.NET is Decimal.
What is the MSDN saying about Decimal.

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding.

MSDN SOURCE

Please rate this snippet

How to choose a font using FontDialog in C# and VB.NET

To choose a font using FontDialog in C# and VB.NET you can use the following snippet.

Sample C#

using (var dialog = new FontDialog())
{
	if (dialog.ShowDialog() != DialogResult.Cancel)
	{
		textBox1.Font = dialog.Font;
	}
}

Sample VB.NET

Using dialog = New FontDialog()
	If dialog.ShowDialog() <> DialogResult.Cancel Then
		textBox1.Font = dialog.Font
	End If
End Using

Please rate this snippet

How to select a file using OpenFileDialog in C# and VB.NET

To select a file using OpenFileDialog in C# and VB.NET you can use the following snippet.

Sample C#

private string SelectFileDialog(string initialDirectory=@"C:\")
{
	using (var dialog = new OpenFileDialog())
	{
		dialog.Filter = @"All files (*.*)|*.*";
		dialog.InitialDirectory = initialDirectory;
		dialog.Title = @"Select a file";
		return (dialog.ShowDialog() == DialogResult.OK) ? dialog.FileName : string.Empty;
	}
}

Sample VB.NET

Private Function SelectFileDialog(Optional initialDirectory As String = "C:\") As String
	Using dialog = New OpenFileDialog()
		dialog.Filter = "All files (*.*)|*.*"
		dialog.InitialDirectory = initialDirectory
		dialog.Title = "Select a file"
		Return If((dialog.ShowDialog() = DialogResult.OK), dialog.FileName, String.Empty)
	End Using
End Function

Please rate this snippet

How to choose a color using ColorDialog in C# and VB.NET

To choose a color using ColorDialog in C# and VB.NET you can use the following snippet.

Sample C#

using (var colorDialog = new ColorDialog())
{
	if (colorDialog.ShowDialog() != DialogResult.Cancel)
	{
		var colorChosen = colorDialog.Color;
		textBox1.ForeColor = colorChosen;
		textBox1.BackColor = colorChosen;
	}
}

Sample VB.NET

Using colorDialog = New ColorDialog()
	If colorDialog.ShowDialog() <> DialogResult.Cancel Then
		Dim colorChosen = colorDialog.Color
		textBox1.ForeColor = colorChosen
		textBox1.BackColor = colorChosen
	End If
End Using

Please rate this snippet