tailieunhanh - Teach Yourself the C# Language in 21 Days phần 2

Bây giờ bạn biết làm thế nào để khai báo một biến, điều quan trọng là để tìm hiểu làm thế nào để lưu trữ các giá trị. Sau khi tất cả, mục đích của một biến là để lưu trữ thông tin. Các định dạng cho thông tin lưu trữ trong một biến như sau: | 56 Day 2 Assigning Values to Your Variables Now that you know how to declare a variable it is important to learn how to store values. After all the purpose of a variable is to store information. The format for storing information in a variable is as follows varname value You have already seen that varname is the name of the variable. value is the value that will be stored in the variable. For example to store the number 5 in the variable my_variable you enter the following my_variable 5 You can assign a value to a variable any time after it has been declared. You can even do this at the same time you declare a variable int my_variable 5 A variable s value can also be changed. To change the value you simply reassign a new value my_variable 1010 Listing illustrates assigning values to a couple of variables. It also shows that you can overwrite a value. Listing var Assigning Values to a Variable 01 - A listing to assign and print the value 02 of variables 03 . 04 05 using System 06 07 class var_values 08 09 public static void Main 10 11 declare first_var 12 int first_var 13 14 declare and assign a value to second_var 15 int second_var 200 16 17 assign an initial value to first_var. 18 first_var 5 19 Understanding C Programs 57 Listing continued 20 print values of variables. 21 nfirst_var contains the value 0 first_var 22 second_var contains the value 0 second_var 23 24 assign a new value to the variables. 25 first_var 1010 26 second_var 2020 27 28 print new values. 29 nfirst_var contains the value 0 first_var 30 second_var contains the value 0 second_var 31 32 2 Output Analysis first_var contains the value 5 second_var contains the value 200 first_var contains the value 1010 second_var contains the value 2020 Enter this listing into your editor compile it and execute it. If you need a refresher on how to do this refer to Day 1. The first three lines of this .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.