C#(一)基礎篇—類型與變量

於今日起學習鞏固C#基礎函數

2020-12-01學習

本隨筆用於我的回憶理解,記錄當天學習過程,內容多從書中整理與自我學習瞭解,若有問題麻煩指正ui

之後有時間會單獨分版塊敘述spa

無論什麼語言,都從一個Hello,World開始code

打開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用於引用類庫blog

Main函數是程序入口string

C#是一種強類型語言,在使用任意一個對象前,必須聲明這個對象的類型。it

本身整理了一下io

 

 float類型的賦值後面要加f

float somervar = 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;  //當前水果類型爲蘋果
相關文章
相關標籤/搜索