.net - Formatting strings in C# consistently throughout a large web application -


i'm looking consistent way structure use of formatting strings throughout large web application, , i'm looking recommendations or best practices on way go.

up until i've had static class common formatting e.g.

formatting.formatcurrency

formatting.formatbookingreference

i'm not convinced way go though, i'd prefer use standard way of formatting strings within .net directly , use:

amount.tostring("c")

reference.tostring("000000")

id use iformattable , icustomformatter of our more complicated data structures, i'm struggling more simple existing objects need format (in case int32 datetime).

do define constants "c" , "000000" , use them consistently around whole web app or there more standard way it?

one option use helper class extension methods like

public static class mywebappextensions {     public static string formatcurrency(this decimal d)     {         return d.tostring("c");     } } 

then anywhere have decimal value do

decimal d = 100.25; string s = d.formatcurrency(); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -