unity3D-游戏/AR/VR在线就业班 C#入门 变量和数据类型
C#的变量和常量
常量:字面值常量+const常量
//声明并初始化整型常量a
const int a = 9;
Console.WriteLine (a);
//圆周率用常量表示
const float pi=3.1415926f;
Console.WriteLine (pi);
using System;
namespace Lesson04
{
class MainClass
{
public static void Main (string[] args)
{
//声明变量
int level;
//对变量进行初始化
level=6;
//使用变量
Console.WriteLine (level);
}
}
}
float :使用小数类型 不要忘记加f
using System;
namespace Lesson04
{
class MainClass
{
public static void Main (string[] args)
{
//声明变量 类型+变量名;
int level;
//对变量进行初始化
level=6;
//使用变量
Console.WriteLine (level);
//声明一个float类型的变量exp
float exp;
//初始化变量
exp=0.6f;
Console.WriteLine (exp);
}
}
}
string :字符串类型,使用双引号,专门表示文本方面。
using System;
namespace Lesson04
{
class MainClass
{
public static void Main (string[] args)
{
//声明变量 类型+变量名;
int level;
//对变量进行初始化
level=6;
//使用变量
Console.WriteLine (level);
//声明一个float类型的变量exp
float exp;
//初始化变量
exp=0.6f;
Console.WriteLine (exp);
//声明一个string类型的变量str
string str;
//初始化变量
str = "你好老王";
Console.WriteLine (str);
}
}
}