九九热这里直有精品,1区二区三区在线播放,玖玖爱在线观看资源,国产aⅴ综合网,午夜福利男女,日本亚洲欧美三级,日韩无码黄色导航,内射少妇13区,中文字幕高清网

您身邊的軟件定制專家--9年開發(fā)經(jīng)驗為您護航

18678812288
0531-88887250

總結(jié):C#變量,占位符等相關(guān)知識

文章作者:濟南軟件開發(fā) 時間:2016年12月20日

一.  在C#中,“+” 有兩種含義;

 

1.聯(lián)值符號,當(dāng)+左右兩邊只要有一邊是字符或者字符串類型的時候,用“+”表示連接左右兩邊的數(shù)據(jù)。

 

2.數(shù)學(xué)中的加號,參與運算的是字符型的數(shù)據(jù),表示進行數(shù)學(xué)上的加法運算。

 

賦值運算符=(不是數(shù)學(xué)中的等于符號),是C#中最低的運算等級,在最后執(zhí)行。

 

二. 占位符

 

第一個{0}

 

第二個{1}

 

第三個{2}

 

.......

 

例如:Console.WriteLine("姓名{0} 性別{1} 年齡{2}",name,sex,age);

 

復(fù)制代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace 輸出變量與聯(lián)值

{

    class Program

    {

        static void Main(string[] args)

        {

            string name;

            name = "張三";

            int age = 28;

            age = 18; //重復(fù)賦值變量age的值。

            decimal pay = 7600.33m;

 

            //Console.Write("我叫"+name);

            //Console.Write(",今年"+age+"歲,");

            //Console.Write("我的工資是"+pay+"元.");

 

            //Console.WriteLine("我叫"+name+",今年"+age+"歲,"+"我的工資是"+pay+"元.");            

            Console.WriteLine("我叫{0},今年{1}歲,我的工資是{2}元.", name, age, pay);//{0}{1}{2}表示占位符。占位符可以重復(fù)使用,可以省略。

           

            Console.WriteLine("我叫"+name,"今年"+age+"歲了.");//逗號前為第一個參數(shù),console輸出逗號前的第一個參數(shù)。

            Console.WriteLine("{0}我叫" + name, "今年" + age + "歲了.");//{0}"今年" + age + "歲了."代替前面的占位符的變量。

 

 

           

            

            int a = 1;//同為數(shù)字類型的用“+”表示數(shù)學(xué)上的加法。

            //string a = "1";  聯(lián)值符號的用法區(qū)別,左右兩邊只要一邊有字符或者字符串類型用“+”就是聯(lián)值符號。  

            int b = 2;

            Console.WriteLine(a+b);

            Console.WriteLine("1+2");

            Console.ReadKey();

        }

    }

}

復(fù)制代碼

復(fù)制代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace 變量作業(yè)

{

    class Program

    {

        static void Main(string[] args)

        {

            string name = "張三";

            string Tel = "13111111111";

            char sex = '男';

            int age = 25;

            Console.WriteLine("{0},{1},{2},{3}",name,Tel,sex,age);

            Console.ReadKey();

 

 

        }

    }

}

復(fù)制代碼

復(fù)制代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace 變量作業(yè)4

{

    class Program

    {

        static void Main(string[] args)

        {

            string Pho = "SAMSUNG";

            string type = "I9300";

            decimal money = 3799m;

            string weight = "0.3kg";//double weight = 0.3;

            Console.WriteLine("我的手機牌子是{0},型號是{1},手機價格是{2}元,重量是{3}",Pho,type,money,weight);

 

            Console.ReadKey();

        }

    }

}

復(fù)制代碼

 

 

Console.ReadLine();用于接收用戶輸入的數(shù)據(jù),需要定義一個字符串類型(string)的變量來存儲用戶的變量。

 

  string input;

 

  input=Console.ReadLine(); 

 

等價于 string input=Console.ReadLine();

 

復(fù)制代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace 用戶輸入

{

    class Program

    {

        static void Main(string[] args)

        {

           // string input;

            Console.WriteLine("輸入這句話的前面");

            Console.WriteLine("請在這里輸入一句話!");

            string input = Console.ReadLine();

            Console.WriteLine("輸入這句話的后面");

            Console.ReadKey();

 

        }

    }

}

復(fù)制代碼

三. 交換變量數(shù)值

 

若要相互交換兩個變量的數(shù)值,需要借助第三個變量來完成。

 

  int a =5,b=10;

 

  int c;

 

  c = b;

 

  b = a;

 

  a = c;

 

  Console.WriteLine("a={0} b={1}",a,b);

 

  Console.ReadKey();

 

復(fù)制代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace 交換變量

{

    class Program

    {

        static void Main(string[] args)

        {   //交換兩個變量的算法,需要介助第三個變量。

            int a = 5;

            int b = 10;

            int c;

            c = a;

            a = b;

            b = c;

 

            Console.WriteLine("a={0} b={1}",a,b);

 

            Console.WriteLine("a={0} b={1}",b,a);//并不會交換兩個變量的值

            Console.ReadKey();

        }

    }

}


想要了解更多詳情歡迎來電咨詢18678812288
登陸網(wǎng)址:m.h6244.cn。
聯(lián)系人:王經(jīng)理。

依兰县| 临桂县| 喜德县| 斗六市| 赤壁市| 延川县| 固原市| 高陵县| 昌邑市| 东光县| 江源县| 张家界市| 简阳市| 古丈县| 巨鹿县| 祁阳县| 札达县| 恩施市| 江北区| 马龙县| 车险| 阜康市| 安康市| 安塞县| 惠东县| 南平市| 岢岚县| 城步| 忻城县| 大连市| 石渠县| 东辽县| 措美县| 肃宁县| 上思县| 军事| 策勒县| 沙雅县| 合阳县| 波密县| 浏阳市|