Type gettype protected object memberwiseclone public

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: lic string ToString() Predefined Types string An immutable sequence of Unicode characters Reference type Special syntax for literals string s = “I am a string”; C# Type System Type Size (bytes) String System.String 20 minimum Predefined Types string Normally have to use escape characters “\ server\ fileshare\ string s1= “\\\\server\\fileshare\\filename.cs”; Verbatim string literals Most escape sequences ignored Except for “” Verbatim literals can be multi-line @“\ server\fileshare\ string s2 = @“\\server\fileshare\filename.cs”; Types User-defined Types User-defined types Enumerations Arrays Interface enum int, string interface Reference type class Value type struct Function pointer delegate Types Enums An enum defines a type name for a related group of symbolic constants Choices must be known at compile-time Strongly typed No implicit conversions to/from int Can be explicitly converted Operators: +, -, ++, --, &, |, ^, ~, … Can specify underlying type byte, sbyte, short, ushort, int, uint, long, ulong Types Enums enum Color: byte { Red = 1, Green = 2, Blue = 4, Black = 0, White = Red | Green | Blue } Color c = Color.Black; Console.WriteLine(c); Console.WriteLine(c.Format()); // 0 // Black Types Enums All enums derive from System.Enum Provides methods to determine underlying type test if a value is supported initialize from string constant retrieve all values in enum … Types Arrays Arrays allow a group of elements of a specific type to be stored in a contiguous block of memory Arrays are reference types Derived from System.Array Zero-based Can be multidimensional Arrays know their length(s) and rank Bounds checking Types Arrays Declare int primes; Allocate int primes = new int[9]; Initialize int prime = new int {1,2,3,5,7,11,13,17,19}; int prime = {1,2,3,5,7,11,13,17,19}; Access and assign prime2[i] = prime[i]; Enumerate foreach (int i in prime) Console.WriteLine(i); Types Arrays Multidimensional arrays Rectangular int[,] matR = new int[2,3]; Can initialize declaratively int[,] matR = new int[2,3] { {1,2,3}, {4,5,6} }; Jagged An array of arrays int matJ = new int[2]; Must initialize procedurally Types Interfaces An interface defines a contract Includes methods, properties, indexers, events Any class or struct implementing an interface must support all parts of the contract Interfaces provide polymorphism Many classes and structs may implement a particular interface Contain no implementation Must be implemented by a class or struct Types Classes User-defined reference type Similar to C++, Java classes Single class inheritance Multiple interface inheritance Types Classes Members Constants, fields, methods, operators, constructors, destructors Properties, indexers, events Static and instance members Member access public, protected, private, internal, protected internal Default is private Instantiated with new operator Types Structs Similar to classes, but User-defined value type Always inherits from object Ideal for lightweight objects int, float, double, etc., are all structs User-defined “primitive” types Complex, point, rectang...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online