property
آخر تحديث: منذ 0 ثانية
· 16 مشاهدة
- صح، كل نوع بيانات في Dart (وكتير من اللغات) عنده خصائص (properties) خصوصًا الأنواع المركبة والنصوص، والخصائص دي بتديك معلومات عن القيمة بدون ما تنفّذ دالة.
- مثال:
Stringفيهlength,isEmpty,codeUnits;Listفيهlength,isEmpty,first,last;Mapفيهkeys,values; حتىintلهbitLength. - في Dart الخصائص تُستخدم بدون
(), أما الدوال (functions/methods) بتجي بين قوسين. - لو عايز نعدّل أو نستعرض خصائص النوع اللي بتشتغل عليه، قولي النوع ونركّز على اللي محتاجه (مثلاً List أو custom class).
String Properties
length: number of characters.isEmpty/isNotEmpty: whether the string has no text.codeUnits: list of UTF-16 code units.runes: Unicode code points (good for emojis/Arabic).hashCode: machine value for hashing.runtimeType: shows the type (String).
These are accessed without (). Use them when you just need info, not to modify the string.
length vs index
- In a Dart
String,lengthreturns how many characters it holds. - Since indexing starts at
0, the highest valid index is alwayslength - 1. - So when you take any
indexand add1, you get the position count from1(which matcheslengthwhen you reach the last character). - Example:
"Dart"haslength == 4, indexes0..3, andindex + 1turns3into4.