C#入门官方中文指南
类 型 和 变 量 类型和变量 类型和变量
1.类型和变量
C#里的变量类型,也是两类:
值类型Value Type:
sbyte、short、int、longbool、float、double、char
引用类型 Reference Type:
object, string , ...,自定义的class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp基础语法
{
class Program
{
static void Main(string[] args)
{
int a = 12;
int b = a + 100;
Console.WriteLine("结果为:" + b);
}
}
}
2.控制台输出
字符串的拼接:
string a = "numbers: "+ 66;
其中,一个string和一个int拼接
字符串的格式化:
string str = string.Format("你好:{0},人民:{1}",1314,521);
其中,{0}表示第1个参数,{1}为第2个参数.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp基础语法
{
class Program
{
static void Main(string[] args)
{
string a = "numbers: " + 66;
string str = string.Format("你好:{0},人民:{1}", 1314, 521);
Console.WriteLine("结果为:" + a);
Console.WriteLine(str);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp基础语法
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("numbers: " + 66);
Console.WriteLine("你好:{0},人民:{1}", 1314, 521);
}
}
}
1 Console.WriteLine()是静态方法
2 C#里的方法名以大写开头