Common Type System. Value and reference types in C# презентация

AGENDA Common Type System Data Type Class Hierarchy class Object Intrinsic Data Types Variable Declaration and Initialization Implicitly Typed Local Variables C# Nullable Types. ?? Operator Value and Reference Types Shallow

Слайд 1Common Type System. Value and reference types in C#.

02.02.2013 by L.Klakovych
Reviewed:

20/03/2014 by V.Bartish

Слайд 2AGENDA
Common Type System
Data Type Class Hierarchy
class Object
Intrinsic Data Types
Variable Declaration and

Initialization
Implicitly Typed Local Variables
C# Nullable Types. ?? Operator
Value and Reference Types
Shallow and deep copy



Слайд 3Common Type System
CTS – common type sestem:
defines how types are declared,

used, and managed in the common language runtime,
is an important part of the runtime's support for cross-language integration.
CTS performs the following functions:
Establishes a framework that helps enable cross-language integration, type safety, and high-performance code execution.
Provides an object-oriented model that
supports the complete implementation
of many programming languages.
Defines rules that languages must follow,
which helps ensure that objects written in
different languages can interact with each
other.
Provides a library that contains the
primitive data types
( Boolean, Byte, Char, Int32, and UInt64)


Слайд 4The Data Type Class Hierarchy
A globally unique identifier (GUID ) is

a statistically unique 128-bit number

Слайд 5Base class Object
Equals() is used to compare object references, not the

state of the object. ValueType class overrides it for the value-based comparisons.

GetHashCode() returns an int that identifies a specific object instance.

ToString() returns a string representation of this object - fully qualified name

MemberwiseClone() creates a shallow copy by creating a new object, and then copying the nonstatic fields of the current object to the new object. If a field is a reference type, the reference is copied but the referred object is not;


Слайд 6Intrinsic Data Types


Слайд 7Variable Declaration and Initialization
It is a compiler error to make use

of a local variable before assigning an initial value.
All intrinsic data types support a default constructor. We can create a variable using the new keyword, which automatically sets the variable to its default value:
• bool variables are set to false.
• Numeric data is set to 0 (or 0.0 in the case of floating-point data types).
• char variables are set to a single empty character.
• BigInteger variables are set to 0. (from System.Numerics.dll)
• DateTime variables are set to 1/1/0001 12:00:00 AM.
• Object references (including strings) are set to null.

Слайд 8Variable Declaration and Initialization





It is more cumbersome to use the new

keyword when creating a basic data type variable:

Слайд 9Implicitly Typed Local Variables


Слайд 10C# Nullable Types
In C#, the ? suffix notation is a shorthand

for creating an instance of the generic System.Nullable structure type.

Слайд 11C# Nullable Types and operator ??

?? Operator allows you to assign

a value to a nullable type if the retrieved value is in fact null.

Слайд 12Value and Reference Types


Слайд 13Value and Reference Types


Слайд 14Value and References Types, Assignment Operator


Слайд 15Parameter Modifiers



Слайд 16Passing Reference Types by Value and by Reference


Слайд 17Shallow and deep copy
If you have a class or structure that

contains only value types, implement your Clone() method using MemberwiseClone():

If you have a custom type that maintains other reference types, you might want to create a new object that takes into account each reference type member variable, in order to get a “deep copy.”

public class Point : ICloneable
{
private int x, y;

public object Clone()
{ return this.MemberwiseClone(); }
}

public class Rectangle: ICloneable{
public object Clone()
{
// First get a shallow copy.
Rectangle newRect =
(Rectangle)this.MemberwiseClone();
// Then fill in the gaps.
newRect.P1 = (Point)this.P1.Clone();
//…
return newRect;
}


Слайд 18References
MSDN:Common Type System
Built-in Data Types
Value and Reference Types
Object class


Слайд 19Questions ?


Обратная связь

Если не удалось найти и скачать презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:

Email: Нажмите что бы посмотреть 

Что такое ThePresentation.ru?

Это сайт презентаций, докладов, проектов, шаблонов в формате PowerPoint. Мы помогаем школьникам, студентам, учителям, преподавателям хранить и обмениваться учебными материалами с другими пользователями.


Для правообладателей

Яндекс.Метрика