Learning C# - Everyday learning

Thursday, June 3, 2010

Namespaces can be nested. So I can have one namespace within another.
System is most frequently used namespace
Inside System namespace is class called Console, which contains static methods.

The datatypes are defined as classes, they are equipped with methods. ToString() is a common method for all the datatypes.

We can use pointers in C# but we have to mark the functions that use pointers as 'unsafe'

unsafe static void Main()

To read numbers from console window use Parse method.
 Number = int.Parse(Console.ReadLine());

Formatting numbers
Character Used For
c C Currency values
d D Decimal numbers
e E Scientific numeric display such as 1.45e5
f F Fixed decimal numbers
g G General and most common type of numbers
n N Natural numbers
r R Roundtrip formatting
x X Hexadecimal formatting
p P Percentages
var Distance = 248.38782;
Distance.ToString("E") would result var into 2.483878E+002

var NewColor = 3478;
NewColor.ToString("X") would result var into D96

var HSalary = 22.74121
HSalary.ToString("c") would result var into $22.74

var HoursWorked = 35.5018473;
HoursWorked.ToString("F") would result var into 35.50

Labels: ,

0 comments: