Int32 123 j 123 types unified type system benefits of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: m.Int32 123 j 123 Types Unified Type System Benefits of boxing Enables polymorphism across all types Collection classes work with all types Eliminates need for wrapper classes Lots of examples in .NET Framework Hashtable t = new Hashtable(); t.Add(0, "zero"); t.Add(1, "one"); string s = string.Format( t.Add(2, "two"); "Your total was {0} on {1}", total, date); Types Unified Type System Disadvantages of boxing Performance cost Types Predefined Types Value Integral types Floating point types decimal bool char Reference object string Predefined Types Value Types All are predefined structs Signed sbyte, short, int, long Unsigned byte, ushort, uint, ulong Character char Floating point Logical float, double, decimal bool Predefined Types Integral Types C# Type System Type Size (bytes) Signed? sbyte System.Sbyte 1 Yes short System.Int16 2 Yes int System.Int32 4 Yes long System.Int64 8 Yes byte System.Byte 1 No ushort System.UInt16 2 No uint System.UInt32 4 No ulong System.UInt64 8 No Predefined Types Floating Point Types Follows IEEE 754 specification Supports ± 0, ± Infinity, NaN C# Type System Type Size (bytes) float System.Single 4 double System.Double 8 Predefined Types decimal 128 bits Essentially a 96 bit value scaled by a power of 10 Decimal values represented precisely Doesn’t support signed zeros, infinities or NaN C# Type System Type Size (bytes) decimal System.Decimal 16 Predefined Types Integral Literals Integer literals can be expressed as decimal or hexadecimal U or u: uint or ulong L or l: long or ulong UL or ul: ulong 123 0x7B 123U 123ul 123L // // // // // int Hexadecimal Unsigned Unsigned long Long Predefined Types Real Literals F or f: float D or d: double M or m: decimal 123f 123D 123.456m 1.23e2f 12.3E1M // // // // // Float Double Decimal Float Decimal Predefined Types bool Represents logical values Literal values are true and false Cannot use 1 and 0 as boolean values No standard conversion between other types and bool C# Type System Type Size (bytes) bool System.Boolean 1 (2 for arrays) Predefined Types char Represents a Unicode character Literals ‘A’ ‘\u0041’ ‘\x0041’ ‘\n’ // Simple character // Unicode // Unsigned short hexadecimal // Escape sequence character C# Type System Type Size (bytes) Char System.Char 2 Predefined Types char Escape sequence characters (partial list) Char Meaning Value \’ Single quote 0x0027 \” Double quote 0x0022 \\ Backslash 0x005C \0 Null 0x0000 \n New line 0x000A \r Carriage return 0x000D \t Tab 0x0009 Predefined Types Reference Types Root type object Character string string Predefined Types object Root of object hierarchy Storage (book keeping) overhead 0 bytes for value types 8 bytes for reference types An actual reference (not the object) C# Type System Type Size (bytes) object System.Object 0/8 overhead Predefined Types object Public Methods public bool Equals(object) protected void Finalize() public int GetHashCode() public System.Type GetType() protected object MemberwiseClone() pub...
View Full Document

This note was uploaded on 04/04/2014 for the course CS 5950 taught by Professor Staff during the Summer '08 term at Western Michigan.

Ask a homework question - tutors are online