تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
استخدام Readonly و Constant في ال C#
#1
كاتب الموضوع : AhmedEssawy

كود :
// NOTE: This code snippet is designed for VS.NET 2005 or later.
public class Test
{
// Note that constants are static by default and readonly
// variables are not.
// A constant, "Hello!", must be provided at the time the constant
// is:
public const string Hello = "Hello!";
// This constant will also work:
public const int Number = 1;
// This will throw an exception because DateTime.Now is NOT a
public constant public const DateTime Now = DateTime.Now;
// This constant will throw an error because it's not set:
public const short ShortNumber;
// A readonly, "Hey!", can be set at runtime or at declaration time
// and doesn't need to be a literal value:
public readonly String Hey1 = "Hey!";
// Since a readonly variable doesn't need to be set at declaration
// time, the following will work; variable Hey2 can be set ONLY in
// the constructor of the class:
public readonly String Hey2;
// Unlike constant, readonly variables can have non-literal values:
public readonly DateTime RightNow = DateTime.Now;
}
}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  استخدام دوال مكتبة من ملف DLL بدون إضافته كمرجع Reference @@أبورائد@@ 7 7,905 18-11-21, 05:30 AM
آخر رد: kaled2025
  مثال بسيط لتغيير طريقة استخدام اداة العنان Label مع الشرح RaggiTech 0 3,051 20-10-12, 11:50 AM
آخر رد: RaggiTech
  سورس كود ملف ربط ديناميكى لتحديد فتره استخدام البرنامج RaggiTech 0 2,915 17-10-12, 08:52 PM
آخر رد: RaggiTech
  حمايه استخدام البرنامج عن طريق ملف خارجى RaggiTech 0 2,564 17-10-12, 08:51 PM
آخر رد: RaggiTech
  طريقة استخدام مكتبة internet download manager في برنامجك !! RaggiTech 0 2,268 17-10-12, 08:07 PM
آخر رد: RaggiTech
  استخدام مجال الأسماء My.Computer لمعرفة هل ازرارالوظائف تستخدم ام لاكزر Ctrl و خلافه RaggiTech 0 2,080 17-10-12, 06:59 PM
آخر رد: RaggiTech
  استخدام شخصيات مايكروسوفت مع مكتبة speech RaggiTech 0 2,071 17-10-12, 06:59 PM
آخر رد: RaggiTech
  كيفيه استخدام ال progress bar RaggiTech 0 1,836 17-10-12, 05:18 PM
آخر رد: RaggiTech
  كيفية استخدام شريط التحميل Progress bar RaggiTech 0 2,161 17-10-12, 05:16 PM
آخر رد: RaggiTech
  استخدام Row.Find في ADO.net RaggiTech 0 1,807 17-10-12, 04:45 PM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم