0

How can Formatting and Retrieving Information in c# ?

2nd Dec 2016, 10:32 AM
MohammadReza Dehnashi
MohammadReza Dehnashi - avatar
1 Resposta
0
using System; class Picts { public static void Main() { int var1 = 1234; float var2 = 12.34F; // Zero formatter Console.WriteLine(“\nZero...”); Console.WriteLine(“{0} -->{0:0000000}”, var1); Console.WriteLine(“{0} -->{0:0000000}”, var2); // Space formatter Console.WriteLine(“\nSpace...”); Console.WriteLine(“{0} -->{0:0####}<--”, var1); Console.WriteLine(“{0} -->{0:0####}<--”, var2); // Group separator and multiplier (,) Console.WriteLine(“\nGroup Multiplier...”); Console.WriteLine(“{0} -->{0:0,,}<--”, 1000000); Console.WriteLine(“Group Separator...”); Console.WriteLine(“{0} -->{0:##,###,##0}<--”, 2000000); Console.WriteLine(“{0} -->{0:##,###,##0}<--”, 3); // Percentage formatter Console.WriteLine(“\nPercentage...”); Console.WriteLine(“{0} -->{0:0%}<--”, var1); Console.WriteLine(“{0} -->{0:0%}<--”, var2); // Literal formatting Console.WriteLine(“\nLiteral Formatting...”); Console.WriteLine(“{0} -->{0:’My Number: ‘0}<--”, var1); Console.WriteLine(“{0} -->{0:’My Number: ‘0}<--”, var2); Console.WriteLine(“\n{0} -->{0:Mine: 0}<--”, var1); Console.WriteLine(“{0} -->{0:Mine: 0}<--”, var2); } } // Output Zero... 1234 -->0001234 12.34 -->0000012 Space... 1234 -->01234<-- 12.34 -->00012<-- Group Multiplier... 1000000 -->1<-- Group Separator... 2000000 -->2,000,000<-- 3 -->3<-- Percentage... 1234 -->123400%<-- 12.34 -->1234%<-- Literal Formatting... 1234 -->My Number: 1234<-- 12.34 -->My Number: 12<-- 1234 -->Mine: 1234<-- 12.34 -->Mine: 12<--
2nd Dec 2016, 10:40 AM
MohammadReza Dehnashi
MohammadReza Dehnashi - avatar