var، كشف حساب

التصريح عن متغير.

// Syntax for declaring a variable of global scope or function scope.
var name1 [: type1] [= value1] [, ... [, nameN [: typeN] [= valueN] ]]

// Syntax for declaring a variable field within a class.
 [attributes] [modifiers] var name1 [: type1] [= value1] [, ... [, nameN [: typeN] [= valueN].]]

الوسيطات

  • attributes
    اختياري. السمات التي عنصر تحكم رؤية والسلوك من الحقل.

  • معدلات
    اختياري. المعدلات التي تتحكم في رؤية والسلوك من الحقل.

  • name1،..., nameN
    مطلوبة. أسماء المتغيرات التي يتم تعريفها.

  • type1،..., typeN
    اختياري. The أنواع of the متغيرات being declared.

  • value1, ..., valueN
    اختياري. The القيمة الإفتراضية تعيين إلى the متغير.

ملاحظات

استخدم the var كشف إلى declare متغيرات. A متغير may be حدود إلى a specific نوع بيانات إلى تعليمات provide تأمين النوع. These متغيرات may be assigned قيم when they are declared, و these قيم may be تم تغييره later في the برنامج نصي. متغيرات that are not بوضوح initialized are assigned the القيمة افتراضية of غير معرّف (coerced إلى the نوع of the متغير if necessary).

A متغير حقل في a فئة هو similar إلى a عمومي أو دالة متغير, except that it هو scoped إلى the فئة و it can have متنوع السمات governing its رؤية و usage.

مثال

The following مثال illustrates some uses of the var كشف.

class Simple {
   // A field declaration of the private Object myField.
   private var myField : Object;
   // Define sharedField to be a static, public field.
   // Only one copy exists, and is shared by all instances of the class.
   static public var sharedField : int = 42;
}
var index;
var name : String = "Thomas Jefferson";
var answer : int = 42, counter, numpages = 10;
var simpleInst : Simple = new Simple;

المتطلبات

Version 1

راجع أيضًا:

المرجع

ثابتة، كشف حساب

دالة، كشف حساب

عامل التشغيل new

المبادئ

نطاق متغيرات و الثوابت

نوع تعليق توضيحي

موارد أخرى

المُعَدِّلات