Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, June 03, 2011

Using C# String.Format “{0:p0}” without the leading space before percentage sign

Simplest expresssion is:  

String.Format("{0:0%}", 0.10)

A more elegant solution is:  

Use the NumberFormatInfo.PercentPositivePattern Property:
NumberFormatInfo numberInfo = new NumberFormatInfo();
numberInfo.PercentPositivePattern = 1;
Console.WriteLine(String.Format("{0}", 0.10.ToString("P0",numberInfo)));

Friday, August 20, 2010

Robert The Grey: I don’t want your stinkin’ code comments

Robert The Grey: I don’t want your stinkin’ code comments: "I just read a fantastic thought experiment being put forward and trialled by Jesse Liberty at the moment. I’ve written this post in support ..."

Tuesday, April 27, 2010

Creating custom .NET Exceptions in C#

public class XyzlException : Exception
{
public XyzlException (string errorMessage, Exception inner) : base(errorMessage, inner)
{}
}


You can pass in a custom error message to your new Exception type.

Just try it out...