Podcast
Questions and Answers
ما هو المصطلح المستخدم لوصف حقل في الذاكرة يتم فيه تخزين البيانات ويمكن تغيير محتوياته عدة مرات داخل البرنامج؟
ما هو المصطلح المستخدم لوصف حقل في الذاكرة يتم فيه تخزين البيانات ويمكن تغيير محتوياته عدة مرات داخل البرنامج؟
- الفئة (Class)
- الثابت (Constant)
- المتغير (Variable) (correct)
- الإجراء (Method)
أي من الخيارات التالية يمثل الفرق الأساسي بين المتغيرات والثوابت في لغة #C؟
أي من الخيارات التالية يمثل الفرق الأساسي بين المتغيرات والثوابت في لغة #C؟
- المتغيرات يجب تعريفها داخل الإجراءات، بينما الثوابت يمكن تعريفها على مستوى النموذج.
- المتغيرات يمكن تغيير قيمتها أثناء تنفيذ البرنامج، بينما الثوابت تحتفظ بقيمتها الثابتة. (correct)
- المتغيرات تستخدم لتخزين أنواع مختلفة من البيانات، بينما الثوابت مخصصة للأرقام فقط.
- المتغيرات حساسة لحالة الأحرف، بينما الثوابت ليست كذلك.
أي من القواعد التالية يجب اتباعها عند تسمية المتغيرات في #C؟
أي من القواعد التالية يجب اتباعها عند تسمية المتغيرات في #C؟
- يمكن أن يكون الاسم مطابقًا للكلمات المحجوزة في اللغة.
- يجب أن يبدأ الاسم برقم.
- يمكن أن يحتوي الاسم على رموز وعلامات خاصة.
- يجب ألا يحتوي الاسم على مسافات. (correct)
ماذا يحدث إذا حاولت استخدام متغير في #C قبل الإعلان عنه؟
ماذا يحدث إذا حاولت استخدام متغير في #C قبل الإعلان عنه؟
أي نوع من البيانات يجب استخدامه لتخزين عدد صحيح يتراوح بين -32,768 و 32,767؟
أي نوع من البيانات يجب استخدامه لتخزين عدد صحيح يتراوح بين -32,768 و 32,767؟
أي من أنواع البيانات التالية يستخدم لتخزين قيمة منطقية (إما صح أو خطأ) في #C؟
أي من أنواع البيانات التالية يستخدم لتخزين قيمة منطقية (إما صح أو خطأ) في #C؟
ما هي القيمة الافتراضية للمتغير المنطقي (bool
) في #C إذا لم يتم تحديد قيمة ابتدائية له؟
ما هي القيمة الافتراضية للمتغير المنطقي (bool
) في #C إذا لم يتم تحديد قيمة ابتدائية له؟
أي من العمليات التالية تعتبر تخصيصًا صحيحًا لقيمة المتغير age
من النوع int
؟
أي من العمليات التالية تعتبر تخصيصًا صحيحًا لقيمة المتغير age
من النوع int
؟
ماذا تعني حساسية حالة الأحرف (Case Sensitive) في سياق أسماء المتغيرات في #C؟
ماذا تعني حساسية حالة الأحرف (Case Sensitive) في سياق أسماء المتغيرات في #C؟
أي من الخيارات التالية يعرض طريقة صحيحة للإعلان عن متغير باسم userName
من النوع string
وتخصيص القيمة "John" له في سطر واحد؟
أي من الخيارات التالية يعرض طريقة صحيحة للإعلان عن متغير باسم userName
من النوع string
وتخصيص القيمة "John" له في سطر واحد؟
في #C، أين يجب تعريف المتغيرات لكي تكون متاحة لجميع الإجراءات (methods) داخل نفس النموذج (Form)؟
في #C، أين يجب تعريف المتغيرات لكي تكون متاحة لجميع الإجراءات (methods) داخل نفس النموذج (Form)؟
ماذا يطلق على المتغيرات التي يتم تعريفها داخل إجراء معين في #C؟
ماذا يطلق على المتغيرات التي يتم تعريفها داخل إجراء معين في #C؟
ما هو المقصود بـ "فترة حياة المتغير" (Life Time) في #C؟
ما هو المقصود بـ "فترة حياة المتغير" (Life Time) في #C؟
في #C، كيف تعلن عن ثابت من النوع float
باسم PI
وتخصص له القيمة 3.14؟
في #C، كيف تعلن عن ثابت من النوع float
باسم PI
وتخصص له القيمة 3.14؟
لماذا نستخدم الثوابت المعرفة من قبل المبرمج (const) بدلاً من كتابة القيم مباشرة في الكود؟
لماذا نستخدم الثوابت المعرفة من قبل المبرمج (const) بدلاً من كتابة القيم مباشرة في الكود؟
أي دالة (method) تستخدم لتحويل قيمة رقمية إلى نص (string) في #C؟
أي دالة (method) تستخدم لتحويل قيمة رقمية إلى نص (string) في #C؟
ما هي وظيفة الدالة ()Parse في #C؟
ما هي وظيفة الدالة ()Parse في #C؟
إذا كان لديك متغير باسم number
من النوع int
وقيمته 123، كيف يمكنك عرضه في مربع نص باسم textBox1
؟
إذا كان لديك متغير باسم number
من النوع int
وقيمته 123، كيف يمكنك عرضه في مربع نص باسم textBox1
؟
في #C، ماذا يحدث إذا حاولت جمع قيمتين نصيتين (string) باستخدام العامل +؟
في #C، ماذا يحدث إذا حاولت جمع قيمتين نصيتين (string) باستخدام العامل +؟
لنفترض أن لديك مربع نص باسم textBox1
يحتوي على الرقم "25" ومربع نص باسم textBox2
يحتوي على الرقم "10". ما هي نتيجة الكود التالي: textBox3.Text = textBox1.Text + textBox2.Text;
؟
لنفترض أن لديك مربع نص باسم textBox1
يحتوي على الرقم "25" ومربع نص باسم textBox2
يحتوي على الرقم "10". ما هي نتيجة الكود التالي: textBox3.Text = textBox1.Text + textBox2.Text;
؟
كيف يمكنك تحويل المتغير floatNumber
الذي قيمته 3.14 إلى النوع int
؟
كيف يمكنك تحويل المتغير floatNumber
الذي قيمته 3.14 إلى النوع int
؟
ما هي وظيفة الكلمة المفتاحية ToString()
؟
ما هي وظيفة الكلمة المفتاحية ToString()
؟
أي طريقة تصف بشكل صحيح كيفية تعامل #C مع العمليات الحسابية عند تخصيص قيمة لمتغير؟
أي طريقة تصف بشكل صحيح كيفية تعامل #C مع العمليات الحسابية عند تخصيص قيمة لمتغير؟
ماذا يحدث عند محاولة تعيين قيمة من نوع بيانات أكبر (مثل long
) إلى متغير من نوع بيانات أصغر (مثل int
)؟
ماذا يحدث عند محاولة تعيين قيمة من نوع بيانات أكبر (مثل long
) إلى متغير من نوع بيانات أصغر (مثل int
)؟
في أي جزء من الكود يتم تعريف المتغيرات العامّة (Global Variables)؟
في أي جزء من الكود يتم تعريف المتغيرات العامّة (Global Variables)؟
أيٌ من الخيارات التالية يصف بشكلٍ صحيح نطاق المتغير المحلي (Local Variable)؟
أيٌ من الخيارات التالية يصف بشكلٍ صحيح نطاق المتغير المحلي (Local Variable)؟
في #C, ما هي النتيجة المتوقعة للكود التالي؟
int a = 5; a = 2 * a + 2;
في #C, ما هي النتيجة المتوقعة للكود التالي؟
int a = 5; a = 2 * a + 2;
ما هي الكلمة المفتاحية التي تستخدم لتعريف متغير لا يمكن تغيير قيمته بعد الإعلان عنه؟
ما هي الكلمة المفتاحية التي تستخدم لتعريف متغير لا يمكن تغيير قيمته بعد الإعلان عنه؟
أي نوع من المتغيرات يتم تهيئته تلقائيًا بالقيمة 0
إذا لم يتم تحديد قيمة ابتدائية له؟
أي نوع من المتغيرات يتم تهيئته تلقائيًا بالقيمة 0
إذا لم يتم تحديد قيمة ابتدائية له؟
لنفترض أن لديك الكود التالي في #C:
double x = 5.7; int y = Convert.ToInt32(x);
ما هي قيمة المتغير y
بعد تنفيذ هذا الكود؟
لنفترض أن لديك الكود التالي في #C:
double x = 5.7; int y = Convert.ToInt32(x);
ما هي قيمة المتغير y
بعد تنفيذ هذا الكود؟
في #C، ما هي الطريقة الصحيحة لتعريف متغير سلسلة نصية باسم message
وتعيين القيمة "Hello World" له؟
في #C، ما هي الطريقة الصحيحة لتعريف متغير سلسلة نصية باسم message
وتعيين القيمة "Hello World" له؟
ماذا يحدث إذا قمت بتعريف متغيرين بنفس الاسم داخل نفس النطاق (scope) في #C؟
ماذا يحدث إذا قمت بتعريف متغيرين بنفس الاسم داخل نفس النطاق (scope) في #C؟
أي من الخيارات التالية يمثل النوع الأكثر ملاءمة لتخزين قيمة عددية صحيحة صغيرة مثل عمر شخص؟
أي من الخيارات التالية يمثل النوع الأكثر ملاءمة لتخزين قيمة عددية صحيحة صغيرة مثل عمر شخص؟
في #C، ماذا تعني الكلمة المفتاحية var
عند تعريف متغير؟
في #C، ماذا تعني الكلمة المفتاحية var
عند تعريف متغير؟
Flashcards
المتغيرات (Variables)
المتغيرات (Variables)
حقول في الذاكرة لتخزين البيانات، قابلة للتغيير أثناء البرنامج.
الثوابت (Constants)
الثوابت (Constants)
حقول في الذاكرة قيمتها ثابتة لا تتغير أثناء تشغيل البرنامج.
قواعد تسمية المتغيرات
قواعد تسمية المتغيرات
يجب أن يبدأ بحرف هجائي (a-z, A-Z). حساسة لحالة الأحرف. لا يحتوي على رموز أو علامات خاصة. إذا كان الاسم مكون من أكثر من كلمة، لا تستخدم مسافات أو شرطات. لا يكون كلمة محجوزة في اللغة.
الإعلان عن المتغير
الإعلان عن المتغير
Signup and view all the flashcards
int
int
Signup and view all the flashcards
float
float
Signup and view all the flashcards
string
string
Signup and view all the flashcards
bool
bool
Signup and view all the flashcards
تخصيص القيمة للمتغير
تخصيص القيمة للمتغير
Signup and view all the flashcards
المتغير المحلي
المتغير المحلي
Signup and view all the flashcards
متغير على مستوى النموذج
متغير على مستوى النموذج
Signup and view all the flashcards
المتغيرات العامة
المتغيرات العامة
Signup and view all the flashcards
متغيرات محلية Local Variables) على مستوى الإجراء
متغيرات محلية Local Variables) على مستوى الإجراء
Signup and view all the flashcards
في الذاكرة
في الذاكرة
Signup and view all the flashcards
الثابت
الثابت
Signup and view all the flashcards
أستخدمه مباشرة
أستخدمه مباشرة
Signup and view all the flashcards
تغير طفيف
تغير طفيف
Signup and view all the flashcards
قيمة نصية
قيمة نصية
Signup and view all the flashcards
حتي ولو بالكتابة
حتي ولو بالكتابة
Signup and view all the flashcards
int xx
int xx
Signup and view all the flashcards
Study Notes
- These notes summarize key concepts about variables and constants in C#.
Variables, Constants
- After studying this topic, one should be able to:
- Define variables and constants.
- Differentiate between the use of variables and constants.
- Choose a valid name for a variable.
- Identify invalid variable names.
- Summarize the different types of variables and constants.
- Declare variables and constants.
- Identify the error message that appears when using an undeclared variable.
- Assign values to variables and constants.
- Distinguish between using public variables and local variables.
- Declare public variables and local variables.
- Explain the meaning of a variable's lifetime and scope.
- Differentiate between constants declared by the programmer and constants defined in C#.
- Convert numerical data into character data so that it can be placed in a text box.
- Convert between different data types.
What are Variables?
- Data can be stored in memory without being shown to the user except when necessary.
- Variables are named memory locations which can have data stored in them, for use within programs.
- Variables can store numeric, textual, or other types of values.
- It is necessary to assign a unique name to each variable; the variable can be accessed by its name.
- The value of the variable can be changed at any time by placing new values in it, which replaces the old value.
What are Constants?
- Variables have contents that may change during program execution by commands, not by themselves.
- Constants are memory locations with contents that cannot be changed during program execution.
- In a program to calculate the area of a circle with radius (r):
- The area of the circle varies with the radius.
- The value of (pi) is constant equals (3.14) and does not change.
- The value of (r) can be stored in a (Variable), while the value of (pi) is constant and is stored in (Constant).
Naming Variables
- Everything must have a name.
- A variable's name is used when storing or retrieving values in that variable.
Rules for Naming Variables
- A variable name must begin with a letter.
- Variables are case-sensitive; capitalization must be consistent.
- Names should not contain any special symbols such as periods or question marks.
- Spaces and hyphens are not allowed in multi-word names; use underscores instead.
- Each word in a variable name can begin with a capital letter.
- Variable names cannot be reserved names in the language (e.g., IF, Print, Or).
Common Naming Errors
- A variable name should not start with a digit.
- A variable name should not contain special characters.
- Variables should have names in English letters.
- If a word is reserved by the programming language, it cannot be used as a variable name.
Declaring Variables and Data Types
- Every variable has a type depending on the nature of the data.
- The variable can hold a number, decimal, or text value.
- Each data type has a specific size to reserve memory without wasting space.
- Basic data is either characters or numbers. Numbers are either integers (without fractions) or floating points (with fractions).
- There are variables that can store positive and negative numbers which are called Signed. And Unsigned variables that can store only positive numbers.
- Declaring a variable involves specifying its name and type to reserve the required memory space.
General Form for Variable Declaration
- Datatype Variable Name;
Numerical Data Types: Integers
- The primitive numeric types represent signed integers if a signed modifier is used.
- They conversely represent unsigned integers if that modifier is missing.
Signed Integer Types
- byte: Stores integer values from 0 to 255 and occupies 1 byte.
- sbyte: Stores integer values from -128 to 127 and occupies 1 byte.
- short: Stores integer values from -32,768 to 32,767 and occupies 2 bytes.
- ushort: Stores integer values from 0 to 65,535 and occupies 2 bytes.
- int: Stores integer values from -2,147,483,648 to 2,147,483,647 and occupies 4 bytes.
- uint: Stores integer values from 0 to 4,294,967,295 and occupies 4 bytes.
- long: Stores integer values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and occupies 8 bytes.
- ulong: Stores integer values from 0 to 18,446,744,073,709,551,615 and occupies 8 bytes.
Declaring Numerical Variables With Fractions
- float: Stores fractional numbers and occupies 4 bytes. Its range 1.5 x 10^-45 to 3.4 x 10^38 with 7 decimal places.
- double: Stores fractional numbers and occupies 8 bytes. Its range 5.0 x 10^-324 to 1.7 x 10^308 with 16 decimal places.
- decimal: Stores fractional numbers and occupies 16 bytes. Its range 1.0 x 10^-28 to 7.9 x 10^28 with 29 decimal places.
Declaring Floating Points Variables
- All decimal variables are of type double unless specifically defined as float or decimal.
- When defining decimal, add the letter m or M after the value that will be stored in the variable, and in the case of float, add the letter f or F after the value.
- If the numerical variables are not stored with a value, the default value will be (0).
Logical variables
- Store a value of True (Yes/Correct) or False (No/Wrong).
- If the value of logical variable isn't set, the value is assumed to be false, and it should be noted that the word True or False is written in small letters.
Declaring Variables With text
- string: Variables to set the names of people, sentences or paragraphs depending on the stored characters.
- char: Single characters are stored, and each variable is 2 Bytes in size.
- If the textual variables are not stored with a value, the variable will be Blank.
Dealing with Variables
- This refers to storing the value in the variable and is called (Assignment), or using the value of the variable as its view or using the value of the variable in an arithmetic operation.
Assign a Variable to a Value
- A value can be assigned to a variable directly or through the result of an operation, or with an arithmetic operation.
- When a numerical value is assigned to variables, it is done in the previous codes, but in the case of String variables, the value must be placed between double quotes.
- After declaring a variable and storing the required value in it, it can be used in different ways.
- If you have a variable named Age, you can store the value of this variable in another variable as follows:
- Xx = Age;
- The computer handles the first statement as assigning the value 30 to the variable Sum.
- The second statement calculates the value of the right side of the (=) sign, by placing the value of the Sum variable, which equals 30, and the right side becomes 30 + 10 and after performing the addition operation, the result equals (40).
- The output result (40) is stored in the variable to the left of the sign (=), which means that the value of the Sum variable will change from the value (30) to a new value, which is (40).
- It is possible to put the value of the variable Age in a text box as follows:
- Textbox1 = Age;
- You can display the value of the variable using a message box such as:
- MessageBox.Show (Age);
- Since C#.Net does not convert numerical variables into texts automatically and the text box cannot receive numbers unless it is in the form of texts, the numbers had to be converted to texts.
Variable Declaration Scope
- Variable definitions can be placed in any procedure or in a class that contains this procedure.
- The more limited the scope, the more restricted the use of the variable. Also, this depends on how long you want the variable to retain its value, which is called life time.
- If the variables a, b are defined only in the procedure Button1_Click specific, the procedure Button2_Click of the second button cannot be utilized and dealt with.
- Variables that are defined within a specific procedure cannot be used within another procedure, because they are considered local variables in this case. Only the procedure in which they are defined can use them.
How to Solve the Previous Problem
- It is required when clicking the Button2 button so that the product of the numbers appears in the textBox1 text box, and here the range of the variables must be expanded meaning that all procedures at the form level can use these two variables.
Local Variables at Process Level
- They are defined inside the procedure.
- They range at the level of the procedure in which they were declared, meaning that only this procedure can use these variables, not other procedures.
- These variables retain their value until the procedure is executed, and C#.NET removes them from memory.
Variables at The File or Form Level
- They are the variables that are defined outside the procedures in the part of creating the form.
- They range at the model level and include procedures meaning that the variable is available for any procedure in this model.
- These variables remain in memory and retain their values throughout the operation of the model or file it contains, and end when the model stops.
Global Variables
- They are used if there is more than one window or model inside your project, and you want these variables to be available to all these models.
- Here, such variables are defined in class so that they can be used in all other models and retain their value until the end of the program as will be seen later.
Constants Specific Declared by The Programmer
- These are constants that the programmer defines within the project to serve the purposes of the project, and they must be declared as in variables completely and with the same rules, but with the Const keyword as in the following example:
- const float Tax_Rate = 0.07;
- The advantage to this is so that if the (0.07) must be used multiple times, then it may not be required every number entry to be checked again to ensure that it is correct.
Converting Between Data Types
- #C enables the conversion between different data types, i.e., the character value 250 can be converted to the numerical value 250 and vice versa, as well as for other data types.
- Any value placed between quotation marks is treated as pure text in the code.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.