You are on page 1of 3

STUDENT ID: 2127381

STUDENT NAME: Mlondi Dlamini


MODULE NAME: PN1-Week 2 Assignment 2
Question 1:

Write a C# code to output all the string.format specifiers.

Answer:

using System;

class Program

static void Main()

// Common specifiers

Console.WriteLine("{0}", "Placeholder");

Console.WriteLine("{0:G}", "General");

Console.WriteLine("{0:F}", "Fixed-point");

Console.WriteLine("{0:N}", "Number");

Console.WriteLine("{0:P}", "Percent");

Console.WriteLine("{0:D}", "Decimal");

Console.WriteLine("{0:X}", "Hexadecimal");

Console.WriteLine();

// Numeric specifiers

Console.WriteLine("{0:C}", "Currency");

Console.WriteLine("{0:E}", "Scientific (Exponential)");

Console.WriteLine("{0:G}", "General (Number)");

Console.WriteLine("{0:R}", "Round-trip");

Console.WriteLine("{0:P}", "Percent");

Console.WriteLine();

// Date and time specifiers

Console.WriteLine("{0:d}", "Short date");

Console.WriteLine("{0:D}", "Long date");


Console.WriteLine("{0:t}", "Short time");

Console.WriteLine("{0:T}", "Long time");

Console.WriteLine("{0:f}", "Full date and time (short time)");

Console.WriteLine("{0:F}", "Full date and time (long time)");

Console.WriteLine("{0:g}", "General date and time (short time)");

Console.WriteLine("{0:G}", "General date and time (long time)");

Console.WriteLine("{0:M}", "Month");

Console.WriteLine("{0:Y}", "Year");

You might also like