‏إظهار الرسائل ذات التسميات csharp-basic. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات csharp-basic. إظهار كافة الرسائل

أساسيات البرمجة سي شارب علامات الهروب C# - Character Escapes

أساسيات البرمجة علامات الهروب C# - Character Escapes


علامات الهروب

تستخدم الشرطة المائلة \  كعلامة هروب بحيث اما ان تقوم بطباعة الرموز التي تاليها حرفيا او انها تعطي معنى او امر ما
في الجدول التالي اهم علامات الهروب الشائع استخدامها في سي شارب.

سلسلة الإلغاء
اسم الحرف
ترميز Unicode
\'
علامة اقتباس مفردة
0x0027
\"
علامات اقتباس مزدوجة
0x0022
\\
Backslash
0x005C
\0
Null
0x0000
A
تنبيه
0x0007
\b
Backspace
0x0008
\f
تغذية النموذج
0x000C
n\
New line
0x000A
:-R
حرف إرجاع
0x000D
t\
أفقي علامة تبويب
0x0009
\u
Unicode سلسلة الإلغاء لزوج بديل.
\Unnnnnnnn
\u
Unicode سلسلة الإلغاء
\u0041 = "A"
\v
تبويب عمودية
0x000B
\x
تتابع هروب Unicode مشابهة إلى "\u" فيما عدا ذات طول متغير.
\x0041 = "A"





Ahmed Ata Almahallawi
Freelancer
IT
IT Help Desk,
SEO experience,PHP,C#,ASPX
Al alami st
gaza -jabaliaGaza Strip
Palestine
ahmed.almahallawi@gmail.com
DOB: 05/10/1984
by +Ahmed Almahallawi 
17/12/2013


أساسيات البرمجة سي شارب ماهي التعابير او التعبيرات المنتظمة C# - Regular Expressions

أساسيات البرمجة سي شارب ماهي التعابير او التعبيرات المنتظمة C# - Regular Expressions

أساسيات البرمجة سي شارب ماهي التعابير او التعبيرات المنتظمة C# - Regular Expressions

أساسيات البرمجة سي شارب ماهي التعابير او التعبيرات المنتظمة C# - Regular Expressions


التعابير المنتظمة Regular Expressions:

هي عبارة عن أنماط لنصوص الأدخال في حال تم معالجتها فأنها إما أن تطبع كما هي أو إنها تعطي تعبير ذا معنى.

أنواع التعابير المنتظمة في سي شارب:-

  1. Character escapes
  2. Character classes
  3. Anchors
  4. Grouping constructs
  5. Quantifiers
  6. Backreference constructs
  7. Alternation constructs
  8. Substitutions
  9. Miscellaneous constructs

فئة التعبير المنتظم The Regex Class

هي فئة تستخدم لانشاء التعابير النصية مثل صيغة التحقق من نوع كلمة السر فمثلا يجب ان تحتوي على رموز وحروف وارقام.وهكذا التحقق من الايميل.
التالي أكثر الدول الشائع استخدامها مع فئة التعبير.
التسلسلالدالة والوصف
1public bool IsMatch( string input ) 
تحدد هل النص مطابق للتعبير في مشيد الفئة ام لا
2public bool IsMatch( string input, int startat ) 
تشبه السابق الانها تحدد من اين يبدا مقارنة التعبير 
3public static bool IsMatch( string input, string pattern ) 
تحدد هل النص مطابق للنموذج الممرر من خلال الدالة
4public MatchCollection Matches( string input ) 
تبحث عن نص معين في كافة التعابير الموجودة
5public string Replace( string input, string replacement ) 
يتم استبدال نص وفقا للصيغة معينة بنص اخر
6public string[] Split( string input ) 
مصفوفة تقوم بقسم النص الى عناصر المصفوفة وفقا للصيغة التعبير
في المثال التالي سنبحث عن الكلمات التي تبدأ بالحرف "S"
using System;
using System.Text.RegularExpressions;
namespace RegExApplication
{
 class Program
 {
 private static void showMatch(string text, string expr)
 {
 Console.WriteLine("The Expression: " + expr);
 MatchCollection mc = Regex.Matches(text, expr);
 foreach (Match m in mc)
 {
 Console.WriteLine(m);
 }
 }
 static void Main(string[] args)
 {
 string str = "A Thousand Splendid Suns";
 Console.WriteLine("Matching words that start with 'S': ");
 showMatch(str, @"\bS\S*");
 Console.ReadKey();
 }
 }
}

ناتج الكود

Matching words that start with 'S':
The Expression: \bS\S*
Splendid
Suns
في المثال التالي نبحث عن الكلمات التي تبدأ بحرف "M" وتنتهي بحرف "E".
using System;
using System.Text.RegularExpressions;
namespace RegExApplication
{
 class Program
 {
 private static void showMatch(string text, string expr)
 {
 Console.WriteLine("The Expression: " + expr);
 MatchCollection mc = Regex.Matches(text, expr);
 foreach (Match m in mc)
 {
 Console.WriteLine(m);
 }
 }
 static void Main(string[] args)
 {
 string str = "make maze and manage to measure it";
 Console.WriteLine("Matching words start with 'm' and ends with 'e':");
 showMatch(str, @"\bm\S*e\b");
 Console.ReadKey();
 }
 }
}
ناتج الكود

Matching words start with 'm' and ends with 'e':
The Expression: \bm\S*e\b
make
maze
manage
measure

في المثال التالي نبحث عن الفراغ ونقوم بحذفه.


using System;
using System.Text.RegularExpressions;
namespace RegExApplication
{
 class Program
 {
 static void Main(string[] args)
 {
 string input = "Hello World ";
 string pattern = "\\s+";
 string replacement = " ";
 Regex rgx = new Regex(pattern);
 string result = rgx.Replace(input, replacement);
 Console.WriteLine("Original String: {0}", input);
 Console.WriteLine("Replacement String: {0}", result);
 Console.ReadKey();
 }
 }
}
ناتج الكود 

Original String: Hello World
Replacement String: Hello World


Ahmed Ata Almahallawi
Freelancer
IT
IT Help Desk,
SEO experience,PHP,C#,ASPX

أساسيات البرمجة سي شارب التعليمات قبل المعالجة C# - Preprocessor Directives

أساسيات البرمجة التعليمات قبل المعالجة C# - Preprocessor Directives

التعليمات قبل المعالجة:-

هي تعليمات تعطي المعالج او المجمع Compiler  قبل بدأ عملية المعالجة للكود البرمجي وتبدأ دائما بالرمز #. وجمل التعليمات ليست جمل أكود فهي لا تنتهي بالفاصلة المنقوطة .

معالج السي شارب Compiler ليس له معالج منفصل لمعالجة التعليمات قبل المعالجة النهائية ومع ذلك يتم معالجة التعليمات في حال وجدت .وتستخدم توجيهات المعالج للمساعدة في الترجمة الشرطية فبعكس لغة سي و سي بلس بلس فتستخدم لتوليد الماكرو .

قائمة الاكواد التي يمكن عمل لها معالجة لتعليماتها.

معالجة للتعليماتالوصف
#defineأنها تعرف سلسلة من الأحرفيسمى الرموز.
#undefفإنه يسمح لك  بعدم تعريف الرموز.
#ifأنها تتيح اختبار رمز أو رموز لمعرفة ما اذا كان قيمتها صحيح
#else أنها تسمح لإنشاء مركب توجيهات المشروطة، جنبا إلى جنب مع السابق
#elifمثل السابق
#endifتنهي جملة الشرطية
#lineيتيح لتعديل سطر المترج وانتاج ملف بالاخطأ والتحذيرات
#errorيتيح توليد ملف للاخطأ
#warningيتيح بانتاج ملف تحذيرات
#regionيقوم بانتاج كتلة برمجية بحيث تكون قابلة للتوسع اودمج 
#endregionنهاية الكتلة البرمجية


مثال على تعريف تعليمة برمجية The #define Preprocessor

تعريف الرمز باي
#define symbol
#define PI 
using System;
namespace PreprocessorDAppl
{
   class Program
   {
      static void Main(string[] args)
      {
         #if (PI)
            Console.WriteLine("PI is defined");
         #else
            Console.WriteLine("PI is not defined");
         #endif
         Console.ReadKey();
      }
   }
}

لتحميل الكود ملاحظة الانتظار 5 ثواني عند فتح الرابط حتي يتم تحويلك لرابط التحميل.

ناتج الكود
PI is defined


Ahmed Ata Almahallawi
Freelancer
IT
IT Help Desk,
SEO experience,PHP,C#,ASPX
Al alami st
gaza -jabaliaGaza Strip
Palestine
ahmed.almahallawi@gmail.com
DOB: 05/10/1984
by +Ahmed Almahallawi 
12/12/2013

أساسيات البرمجة ما هو الفرق بين Assembler و Compiler وInterpreter؟


أساسيات البرمجة ما هو الفرق بين Assembler و Compiler وInterpreter؟
أساسيات البرمجة ما هو الفرق بين Assembler و Compiler وInterpreter؟

أساسيات البرمجة ما هو الفرق بين Assembler و Compiler وInterpreter؟


أساسيات البرمجة سي شارب فضاءات الاسماء C# - Namespaces

أساسيات البرمجة فضاءات الاسماء C# - Namespaces

فضاء الاسماء:-

تستخدم فضاء الاسماء لتجميع الفئات ذات النوع الواحد في حزمة وثم تقوم بفصل بين الفئات الاخرى فلا يحدث تعارض في الاسماء الفئات عند تسميتها بنفس الاسماء.

الصيغة العامة للفضاء الاسماء:-

namespace namespace_name
{
   // الكود
}

لتعريف فضاء الاسماء نستخدم الكلمة المحجوزة namespace ثم اسم الافضاء الذي تريده . ولاستدعاء فضاء الاسماء فالكود التي يظهر كيف نستدعى كود السابق.
namespace_name.item_name;
اسم الفضاء ثم نقطة ثم اسم الفئة أو فضاء أخر حتى تصل للفئة.

مثال على فضاء الاسماء

using System;
namespace first_space
{
   class namespace_cl
   {
      public void func()
      {
         Console.WriteLine("Inside first_space");
      }
   }
}
namespace second_space
{
   class namespace_cl
   {
      public void func()
      {
         Console.WriteLine("Inside second_space");
      }
   }
}   
class TestClass
{
   static void Main(string[] args)
   {
      first_space.namespace_cl fc = new first_space.namespace_cl();
      second_space.namespace_cl sc = new second_space.namespace_cl();
      fc.func();
      sc.func();
      Console.ReadKey();
   }
}

ناتج الكود الفضاء الاسماء علما بان فضاء الاسماء استدعي داخلي.


Inside first_space
Inside second_space

تحميل الكود فضاء الاسماء الداخلي 


استخدام  الكلمة المحجوزة Using

تستخدم الكلمة المحجوزة Using لاختصار الكود فبدلا كتابة فضاء الاسماء كله ثم فضاء الاسماء .............. حتى الفئة ثم الدالة فقط نكتب اسم الفئة ثم الدالة فقط فهي تختصر الاستدعاء

مثال على ذلك دالة writeline في الفئة console فهي في فضاء الاسماء system .

Console.WriteLine ("Hello there");

في المثال السابق على فرض اننا استخدمنا Using System.فلذلك لا حاجة لنا لنكتبها بالصيغة التالية .

System.Console.WriteLine("Hello there");


مثال عل استخدام using مع فضاء اسماء  معرف من قبلنا.

using System;
using first_space;
using second_space;

namespace first_space
{
   class abc
   {
      public void func()
      {
         Console.WriteLine("Inside first_space");
      }
   }
}
namespace second_space
{
   class efg
   {
      public void func()
      {
         Console.WriteLine("Inside second_space");
      }
   }
}   
class TestClass
{
   static void Main(string[] args)
   {
      abc fc = new abc();
      efg sc = new efg();
      fc.func();
      sc.func();
      Console.ReadKey();
   }
}

الناتج فضاء الاسماء السابق:-

Inside first_space
Inside second_space

فضاءات الاسماء المتداخلة Nested Namespaces

فضاء الاسماء المتداخلة هي عبارة عن فضاء اسم داخل فضاء اسم وتستخدم لتجميع فضاءات الاسماء داخل فضاء واحد ذو علاقة.

namespace namespace_name1 
{
   // الكود
   namespace namespace_name2 
   {
     //الكود
   }
}

مثال على فضاء الاسماء المتداخل.

using System;
using first_space;
using first_space.second_space;

namespace first_space
{
   class abc
   {
      public void func()
      {
         Console.WriteLine("Inside first_space");
      }
   }
   namespace second_space
   {
      class efg
      {
         public void func()
         {
            Console.WriteLine("Inside second_space");
         }
      }
   }   
}
 
class TestClass
{
   static void Main(string[] args)
   {
      abc fc = new abc();
      efg sc = new efg();
      fc.func();
      sc.func();
      Console.ReadKey();
   }
}

الناتج:-
Inside first_space
Inside second_space





Ahmed Ata Almahallawi
Freelancer
IT
IT Help Desk,
SEO experience,PHP,C#,ASPX
Al alami st
gaza -jabaliaGaza Strip
Palestine
ahmed.almahallawi@gmail.com

DOB: 05/10/1984
by +Ahmed Almahallawi 




11/12/2013




أساسيات البرمجة سي شارب الواجهات C# - Interfaces

أساسيات البرمجة  الواجهات C# - Interfaces

الواجهة هي تعبير نحوئي بنائي يجب على كل الفئات التي ترث الواجهة أن تفعل ما هو في الواجهة وكيف تنفذ ما في الواجهة بمعني تقيد للفئة من ان تقوم بالتعديل على البنية الاساسية اسماء الاكواد وغيرها.
فالواجهة تحتوي على الدوال والخصائص والمتغيرات في صورة تعريف أو إعلان عنها فقط دون ان تحتوي على كود في داخلها.فهى تنشأ هيكل مقياسي للفئات التي ترث الواجهة.

الاعلان عن الواجهة:-

public interface ITransactions
{
   // أعضاء الواجهة
   void showTransaction();
   double getAmount();
}

يقصد بالاعضاء هي الدوال والمتغيرات والخصائص الى اخره

  • مثال على الواجهات او الواجهة:-

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace InterfaceApplication
{

   public interface ITransactions
   {
      // أعضاء الواجهة
      void showTransaction();
      double getAmount();
   }
   public class Transaction : ITransactions
   {
      private string tCode;
      private string date;
      private double amount;
      public Transaction()
      {
         tCode = " ";
         date = " ";
         amount = 0.0;
      }
      public Transaction(string c, string d, double a)
      {
         tCode = c;
         date = d;
         amount = a;
      }
      public double getAmount()
      {
         return amount;
      }
      public void showTransaction()
      {
         Console.WriteLine("Transaction: {0}", tCode);
         Console.WriteLine("Date: {0}", date);
         Console.WriteLine("Amount: {0}", getAmount());

      }

   }
   class Tester
   {
      static void Main(string[] args)
      {
         Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);
         Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);
         t1.showTransaction();
         t2.showTransaction();
         Console.ReadKey();
      }
   }
}

ناتج الكود الواجهات

Transaction: 001
Date: 8/10/2012
Amount: 78900
Transaction: 002
Date: 9/10/2012
Amount: 451900

تحميل الكود السابق الواجهة أو الواجهات

ملاحظة عند التحميل من الرابط انتظر 5 ثواني حتى يتم تحويلك الى الرابط التحميل الاصلي تلقائي وشكرا






Ahmed Ata Almahallawi
Freelancer
IT
IT Help Desk,
SEO experience,PHP,C#,ASPX
Al alami st
gaza -jabaliaGaza Strip
Palestine
ahmed.almahallawi@gmail.com

DOB: 05/10/1984
by +Ahmed Almahallawi 


11/12/2013

أساسيات البرمجة سي شارب مشغل الحمل الزائد C# - Operator Overloading

أساسيات البرمجة مشغل الحمل الزائد C# - Operator Overloading

الحمل الزائد للمشغل:-

المشغل Operator  هو الاداة التي تستخدم  في العمليات الحسابية او المنطقية  الي اخره من المشغلات او المعاملات.الحمل الزائد يعني اعادة تعريف المشغل مع قيم مختلفة من الوسطاء اوالباراميترات.الحمل الزائد للمشغل يجب ان يستخدم الكلمة المحجوزة Static.

مثال على تطبيق الحمل الزائد للمشغل الجمع(+).

using System;

namespace OperatorOvlApplication
{
   class Box
   {
      private double length;      // طول الصندوق
      private double breadth;     // عرض الصندوق
      private double height;      // ارتفاع الصندوق

      public double getVolume()
      {
         return length * breadth * height;
      }
      public void setLength( double len )
      {
         length = len;
      }

      public void setBreadth( double bre )
      {
         breadth = bre;
      }

      public void setHeight( double hei )
      {
         height = hei;
      }
      // الحمل الزائد  لمشغل الجمع لجمع الصندوق 1 +2
      public static Box operator+ (Box b, Box c)
      {
         Box box = new Box();
         box.length = b.length + c.length;
         box.breadth = b.breadth + c.breadth;
         box.height = b.height + c.height;
         return box;
      }

   }

   class Tester
   {
      static void Main(string[] args)
      {
         Box Box1 = new Box();         // الاعلان عن الصندوق1 مننوع صندوق
         Box Box2 = new Box();         //الاعلان عن الصندوق2 من نوع صندوق
         Box Box3 = new Box();         //الاعلان عن الصندوق3 من نوع صندوق
         double volume = 0.0;          // لتخزين قيمة حجم الصندوق

         // تفاصيل الصندوق1
         Box1.setLength(6.0);
         Box1.setBreadth(7.0);
         Box1.setHeight(5.0);

         // تفاصيل الصندوق2
         Box2.setLength(12.0);
         Box2.setBreadth(13.0);
         Box2.setHeight(10.0);

         // حساب حجم الصندوق1
         volume = Box1.getVolume();
         Console.WriteLine("Volume of Box1 : {0}", volume);

         //حساب حجم الصندوق2
         volume = Box2.getVolume();
         Console.WriteLine("Volume of Box2 : {0}", volume);

         // جمع الصندوق 1 و الصندق 2
         Box3 = Box1 + Box2;

         // حجم الصندوق 3
         volume = Box3.getVolume();
         Console.WriteLine("Volume of Box3 : {0}", volume);
         Console.ReadKey();
      }
   }
}

ناتج الحمل الزائد للمشغل

Volume of Box1 : 210
Volume of Box2 : 1560
Volume of Box3 : 5400


ليس جميع المشغلات يمكن عمل لها  حمل زائد Overloading

الجدول التالي يوضح المشغلات التي يمكن عمل حمل زائد والتي لا يمكن عمل حمل زائد.

المشغلالحالة
+, -, !, ~, ++, --نعم يمكن عمل حمل زائد
+, -, *, /, %نعم يمكن عمل حمل زائد
==, !=, <, >, <=, >=نعم يمكن عمل حمل زائد
&&, ||نعم يمكن عمل حمل زائد
+=, -=, *=, /=, %=لا يمكن عمل حمل زائد
=, ., ?:, ->, new, is, sizeof, typeofلا يمكن عمل حمل زائد


مثال موسع على  الحمل الزائد للمشغلات.

using System;

namespace OperatorOvlApplication
{
    class Box
    {
       private double length;      // طول الصندوق
       private double breadth;     // عرض الصندوق
       private double height;      // ارتفاع الصندوق
      
       public double getVolume()
       {
         return length * breadth * height;
       }
      public void setLength( double len )
      {
          length = len;
      }

      public void setBreadth( double bre )
      {
          breadth = bre;
      }

      public void setHeight( double hei )
      {
          height = hei;
      }
      // جمعالحمل الزائد للمشغل ال
      public static Box operator+ (Box b, Box c)
      {
          Box box = new Box();
          box.length = b.length + c.length;
          box.breadth = b.breadth + c.breadth;
          box.height = b.height + c.height;
          return box;
      }
      
      public static bool operator == (Box lhs, Box rhs)
      {
          bool status = false;
          if (lhs.length == rhs.length && lhs.height == rhs.height 
             && lhs.breadth == rhs.breadth)
          {
              status = true;
          }
          return status;
      }
      public static bool operator !=(Box lhs, Box rhs)
      {
          bool status = false;
          if (lhs.length != rhs.length || lhs.height != rhs.height 
              || lhs.breadth != rhs.breadth)
          {
              status = true;
          }
          return status;
      }
      public static bool operator <(Box lhs, Box rhs)
      {
          bool status = false;
          if (lhs.length < rhs.length && lhs.height 
              < rhs.height && lhs.breadth < rhs.breadth)
          {
              status = true;
          }
          return status;
      }

      public static bool operator >(Box lhs, Box rhs)
      {
          bool status = false;
          if (lhs.length > rhs.length && lhs.height 
              > rhs.height && lhs.breadth > rhs.breadth)
          {
              status = true;
          }
          return status;
      }

      public static bool operator <=(Box lhs, Box rhs)
      {
          bool status = false;
          if (lhs.length <= rhs.length && lhs.height 
              <= rhs.height && lhs.breadth <= rhs.breadth)
          {
              status = true;
          }
          return status;
      }

      public static bool operator >=(Box lhs, Box rhs)
      {
          bool status = false;
          if (lhs.length >= rhs.length && lhs.height 
             >= rhs.height && lhs.breadth >= rhs.breadth)
          {
              status = true;
          }
          return status;
      }
      public override string ToString()
      {
          return String.Format("({0}, {1}, {2})", length, breadth, height);
      }
   
   }
    
   class Tester
   {
      static void Main(string[] args)
      {
        Box Box1 = new Box();          // التصريح عن الصندوق1
        Box Box2 = new Box();          // التصريح عن الصندوق2
        Box Box3 = new Box();          // التصرح عن الصندوق3ي
        Box Box4 = new Box();
        double volume = 0.0;   // تخزين القيمة

        // قيم الصندوق1
        Box1.setLength(6.0);
        Box1.setBreadth(7.0);
        Box1.setHeight(5.0);

        // قيم صندوق2
        Box2.setLength(12.0);
        Box2.setBreadth(13.0);
        Box2.setHeight(10.0);

       //طباعة الصندوق
        Console.WriteLine("Box 1: {0}", Box1.ToString());
        Console.WriteLine("Box 2: {0}", Box2.ToString());
        
        // حساب حجم الصندوق 1
        volume = Box1.getVolume();
        Console.WriteLine("Volume of Box1 : {0}", volume);

        // حساب حجم الصندوق2
        volume = Box2.getVolume();
        Console.WriteLine("Volume of Box2 : {0}", volume);

        // جمع الصندوق1+2
        Box3 = Box1 + Box2;
        Console.WriteLine("Box 3: {0}", Box3.ToString());
        // حساب حجم الصندوق3
        volume = Box3.getVolume();
        Console.WriteLine("Volume of Box3 : {0}", volume);

        //مقارنة الصناديق
        if (Box1 > Box2)
          Console.WriteLine("Box1 is greater than Box2");
        else
          Console.WriteLine("Box1 is  greater than Box2");
        if (Box1 < Box2)
          Console.WriteLine("Box1 is less than Box2");
        else
          Console.WriteLine("Box1 is not less than Box2");
        if (Box1 >= Box2)
          Console.WriteLine("Box1 is greater or equal to Box2");
        else
          Console.WriteLine("Box1 is not greater or equal to Box2");
        if (Box1 <= Box2)
          Console.WriteLine("Box1 is less or equal to Box2");
        else
          Console.WriteLine("Box1 is not less or equal to Box2");
        if (Box1 != Box2)
          Console.WriteLine("Box1 is not equal to Box2");
        else
          Console.WriteLine("Box1 is not greater or equal to Box2");
        Box4 = Box3;
        if (Box3 == Box4)
          Console.WriteLine("Box3 is equal to Box4");
        else
          Console.WriteLine("Box3 is not equal to Box4");

        Console.ReadKey();
      }
    }
}

ناتج الكود السابق

Box 1: (6, 7, 5)
Box 2: (12, 13, 10)
Volume of Box1 : 210
Volume of Box2 : 1560
Box 3: (18, 20, 15)
Volume of Box3 : 5400
Box1 is not greater than Box2
Box1 is less than Box2
Box1 is not greater or equal to Box2
Box1 is less or equal to Box2
Box1 is not equal to Box2
Box3 is equal to Box4











Ahmed Ata Almahallawi
Freelancer
IT
IT Help Desk,
SEO experience,PHP,C#,ASPX
Al alami st
gaza -jabaliaGaza Strip
Palestine
ahmed.almahallawi@gmail.com

DOB: 05/10/1984
by +Ahmed Almahallawi 


8/12/2013