C#(一)基礎篇—型別與變數
阿新 • • 發佈:2020-12-01
於今日起學習鞏固C#基礎
2020-12-01
本隨筆用於個人回憶理解,記錄當天學習過程,內容多從書中整理與自我學習瞭解,如有問題麻煩指正
以後有時間會單獨分版塊敘述
不管什麼語言,都從一個Hello,World開始
開啟VS(我用的2017版)--file--new--project--console APP(.Net Framework)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 {class Program { static void Main(string[] args) { Console.WriteLine("hello,world"); Console.ReadKey(); } } }
using用於引用類庫
Main函式是程式入口
C#是一種強型別語言,在使用任意一個物件前,必須宣告這個物件的型別。
自己整理了一下
float型別的賦值後面要加f
floatsomervar = 0.1f
內建型別,可以顯式或隱式的轉換成另一種型別
short x=10;
int y=x;//隱式轉換
x=y;//編譯錯誤
x=(short)y;//顯式轉換
轉化方式取決於型別位元組大小
基本的識別符號,語句與表示式,變數和常量定義介紹就先略過,後續有時間補充
常量有一個提一下
定義一個固定的變數即常量
const float PI=3.141f(後續不可改變值)
列舉
列舉是一種獨特的值型別,可以看作一個常量列表
enum FRUIT { Apple=0, Banana, //值為1 Cherry, //值為2 } FRUIT fruit = FRUIT.Apple; //當前水果型別為蘋果