自動類型轉換:2種不同類型的數據運算,低精度類型會自動轉換為較高精度的類型。
強制類型轉換:無法自動轉換為我們需要的類型,可以用強制類型轉換,比如上例可以這樣完成:
int i=(int)3.0;
數字前面的(int)表示轉換的目標類型為int,3.0會被強制轉換為3。
需要注意, double 型強制轉換為int型將失去小數部分,比如(int)2.8,我們得到的將是2。
強制類型轉換:無法自動轉換為我們需要的類型,可以用強制類型轉換,比如上例可以這樣完成:
int i=(int)3.0;
數字前面的(int)表示轉換的目標類型為int,3.0會被強制轉換為3。
需要注意, double 型強制轉換為int型將失去小數部分,比如(int)2.8,我們得到的將是2。
2016-03-27
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
/*
* 這是一段提示信息
*/
Console.WriteLine("積跬步,至千里");//打印并換行
}
}
}
using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
/*
* 這是一段提示信息
*/
Console.WriteLine("積跬步,至千里");//打印并換行
}
}
}
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();
}
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();
}
2016-03-25
for (int x=1;x<=12 ;x++ )//請填寫代碼
{
Console.WriteLine(x+" ");
}
{
Console.WriteLine(x+" ");
}
2016-03-25