АкушерствоАнатомияАнестезиологияВакцинопрофилактикаВалеологияВетеринарияГигиенаЗаболеванияИммунологияКардиологияНеврологияНефрологияОнкологияОториноларингологияОфтальмологияПаразитологияПедиатрияПервая помощьПсихиатрияПульмонологияРеанимацияРевматологияСтоматологияТерапияТоксикологияТравматологияУрологияФармакологияФармацевтикаФизиотерапияФтизиатрияХирургияЭндокринологияЭпидемиология

System.Object class in C#

Прочитайте:
  1. Class Summary
  2. Class “A” fires
  3. Class “B” fires
  4. Classes in C#.
  5. Classes of Supply
  6. Classes' data members in C#.
  7. Classes' function members in C#.
  8. Creating generic classes in C#.
  9. Extinction of Different Classes of Fires
  10. NET framework classes.

Def: All.NET classes are derived from System.Object. System.object includes all classes, structures, enumerations, delegates and etc.. So if you don’t specify a base class when you define a class, the compiler will automatically think that it derives from Object.

Desc:: Every class is actually derived from System.Object. (Note,ex:for structs this derivation is indirect — a struct is always derived from System.ValueType, which in turn derives from System.Object.)The practical goal of this is that, besides the methods and properties and so on that you define, you also have access to a number of public and protected member methods that have been defined for the Objectclass. These methods are available in all other classes that you define:

-ToString()— A fairly basic, quick-and-easy string representation, use it when you just want a quick idea of the contents of an object, perhaps for debugging purposes. It provides very little choice of how to format the data.

-GetHashCode()— If objects are placed in a data structure known as a map (also known as a hash table or dictionary), it is used by classes that manipulate these structures to determine where to place an object in the structure.

-Equals() and ReferenceEquals()— used for comparing the equality of objects.

-Finalize()—this method is intended as the nearest that C# has to C++ style destructors and is called when a reference object is garbage collected to clean up resources.

-GetType()— Returns an instance of a class derived from System.Type sothis object can provide an extensive range of information about the class of which your object is a member, including base type, methods, properties, and so on.

- MemberwiseClone() -It simply makes a copy of the object and returns a reference (or in the case of a value type, a boxed reference) to the copy.

ex:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{class Program

{static void Main(string[] args)

{var m = Environment.Version;

Console.WriteLine("Тип m: "+m.GetType());

string s = m.ToString();

Console.WriteLine("Моя версия.NET Framework: " + s);

Version v = (Version)m.Clone();

Console.WriteLine("Значение переменной v: "+v);

Console.ReadLine(); } }}

 

 

26. Inheritance in C#.

Def: Inheritance, together with encapsulation and polymorphism, is one of the three primary characteristics (or pillars) of object-oriented programming. It translated as “NAsledovanie”

Descryp: Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. A derived class can have only one direct base class. However, inheritance is transitive. If ClassC is derived from ClassB, and ClassB is derived from ClassA, ClassC inherits the members declared in ClassB and ClassA.

Ex: public class Shape;

{ int x,y;

Public virtual string Draw(string Figure)

{Cons.wr.(Figure);}

}

Class Rectangle: Shape

{ public override string Draw(string Name)

{Cons.Wr(“Rectangle”);}

}

 


Дата добавления: 2015-09-18 | Просмотры: 621 | Нарушение авторских прав



1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |



При использовании материала ссылка на сайт medlec.org обязательна! (0.004 сек.)