基于VS2012完成对C#的初步学习。
目前正在学习《Learning hard:C#学习笔记》 李志著。
如何完成VS2012的安装:https://www.aiweibk.com/6745.html
创建一个控制台应用程序。
1.简单的输出
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//定义输出文本变量
string welcomeText = "Hello,World";
//输出文本到控制台
Console.WriteLine(welcomeText);
//让控制台程序可见,直到用户按下任意字符为止
Console.ReadKey();
}
}
}
按工具栏的启动按钮或键盘上的F5快捷键运行程序。
按任意键退出运行。
2.设置断点与调试
点击红点处设置断点。
按F5或单击工具栏中的启动图标启动调试运行程序,程序在运行到设置断点的位置时会暂停运行。此时断点位置的代码并没有执行。
3.布尔类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 布尔类型
{
class Program
{
static void Main(string[] args)
{
//直接把布尔值赋给bool变量
bool isOverSpeed = false;
int speed = 80;
//把计算结果为bool类型的表达式赋给bool变量
isOverSpeed = speed > 100; //此处speed小于100,结果为false
if (isOverSpeed)
{
Console.WriteLine("你已超速,为了你的安全请减速");
Console.ReadKey();
}
else
{
Console.WriteLine("未超速。");
Console.ReadKey();
}
}
}
}
运行结果为
若想知道另一个结果,将计算结果处的>改为<即可。