AM Pro
06-22-2008, 10:03 AM
السلام عليكم ورحمة الله
هذه بعض التمارين البسيطة عن هذه المواضيع وأتمنى ممن لديه تمارين أخرى عن
( Event , sealed , ... ) ان يطرحها في هذا الموضوع
هذه التمارين جاهزة للعمل فقط انسخ ثم الصق ...
---------------------------------------------------------------------------------------------
abstruct
using System;
using System.Collections.Generic;
using System.Text;
namespace abstruct
{
class Program
{
/// <summary>
/// يجب على الأقل أن نعرف فيه تابع واحد أبستركت
/// ولا نتكب فيه اجسام التوابع ولا قيمة للمتحولات
/// </summary>
abstract class A
{
public int Number;
public abstract int SetGet
{
get;
set;
}
}
class B : A
{
public override int SetGet
{
set
{
Number = value;
}
get
{
return Number;
}
}
}
static void Main(string[] args)
{
//A a = new A(); // error لأن من خصائص الأبستركت أنه لا يعرف منه غرض فهو فقط للإشتقاق
B b = new B();
b.SetGet = 3; // Set Value
Console.WriteLine(b.SetGet); // Get Value
}
}
}
------------------------------------------------------------------------------------
Interface
using System;
using System.Collections.Generic;
using System.Text;
namespace Interface
{
class Program
{
// private or public لا يكتب فيه مجالات الرؤيا //
interface Humane
{
void Movement(); // طريقة الحركة
}
interface Animales
{
void Movement();
}
class Information : Humane, Animales
{
void Humane.Movement()
{
Console.WriteLine("By Tow Legs");
}
void Animales.Movement()
{
Console.WriteLine("By Four Legs"); // طبعا في حيوانات بيمشوا على رجلين بس بيطيروا كمان
}
static void Main(string[] args)
{
Information Info = new Information();
Humane Hu = (Humane)Info;
Hu.Movement();
Animales Anim = (Animales)Info;
Anim.Movement();
}
}
}
}
----------------------------------------------------------------------------------------------
Delegate
using System;
using System.Collections.Generic;
using System.Text;
namespace Delegation
{
class Program
{
delegate void delegation(int Num1 ,int Num2);
sealed
static void SumNumbers(int Num1, int Num2)
{
Console.WriteLine("Sum : " + (Num1 + Num2));
}
static void MultNumbers(int Num1, int Num2)
{
Console.WriteLine("Mult : " + (Num1 * Num2));
}
static void SubNumbers(int Num1, int Num2)
{
Console.WriteLine("Sub : " + (Num1 - Num2));
}
static void Main(string[] args)
{
// هذا التفويض لأكثر من تابع دفعة واحدة //
delegation Del = new delegation(SumNumbers);
Del += MultNumbers;
Del += SubNumbers;
Del(1, 2); // أصبح هذا الغرض من التفويض يضم عمل ثلاثة توابع دفعة واحدة
}
}
}
--------------------------------------
إن كان هناك أي سؤال فأنا جاهز .....
أتمنى لكم التوفيق والنجاح في الدارين
هذه بعض التمارين البسيطة عن هذه المواضيع وأتمنى ممن لديه تمارين أخرى عن
( Event , sealed , ... ) ان يطرحها في هذا الموضوع
هذه التمارين جاهزة للعمل فقط انسخ ثم الصق ...
---------------------------------------------------------------------------------------------
abstruct
using System;
using System.Collections.Generic;
using System.Text;
namespace abstruct
{
class Program
{
/// <summary>
/// يجب على الأقل أن نعرف فيه تابع واحد أبستركت
/// ولا نتكب فيه اجسام التوابع ولا قيمة للمتحولات
/// </summary>
abstract class A
{
public int Number;
public abstract int SetGet
{
get;
set;
}
}
class B : A
{
public override int SetGet
{
set
{
Number = value;
}
get
{
return Number;
}
}
}
static void Main(string[] args)
{
//A a = new A(); // error لأن من خصائص الأبستركت أنه لا يعرف منه غرض فهو فقط للإشتقاق
B b = new B();
b.SetGet = 3; // Set Value
Console.WriteLine(b.SetGet); // Get Value
}
}
}
------------------------------------------------------------------------------------
Interface
using System;
using System.Collections.Generic;
using System.Text;
namespace Interface
{
class Program
{
// private or public لا يكتب فيه مجالات الرؤيا //
interface Humane
{
void Movement(); // طريقة الحركة
}
interface Animales
{
void Movement();
}
class Information : Humane, Animales
{
void Humane.Movement()
{
Console.WriteLine("By Tow Legs");
}
void Animales.Movement()
{
Console.WriteLine("By Four Legs"); // طبعا في حيوانات بيمشوا على رجلين بس بيطيروا كمان
}
static void Main(string[] args)
{
Information Info = new Information();
Humane Hu = (Humane)Info;
Hu.Movement();
Animales Anim = (Animales)Info;
Anim.Movement();
}
}
}
}
----------------------------------------------------------------------------------------------
Delegate
using System;
using System.Collections.Generic;
using System.Text;
namespace Delegation
{
class Program
{
delegate void delegation(int Num1 ,int Num2);
sealed
static void SumNumbers(int Num1, int Num2)
{
Console.WriteLine("Sum : " + (Num1 + Num2));
}
static void MultNumbers(int Num1, int Num2)
{
Console.WriteLine("Mult : " + (Num1 * Num2));
}
static void SubNumbers(int Num1, int Num2)
{
Console.WriteLine("Sub : " + (Num1 - Num2));
}
static void Main(string[] args)
{
// هذا التفويض لأكثر من تابع دفعة واحدة //
delegation Del = new delegation(SumNumbers);
Del += MultNumbers;
Del += SubNumbers;
Del(1, 2); // أصبح هذا الغرض من التفويض يضم عمل ثلاثة توابع دفعة واحدة
}
}
}
--------------------------------------
إن كان هناك أي سؤال فأنا جاهز .....
أتمنى لكم التوفيق والنجاح في الدارين