为了账号安全,请及时绑定邮箱和手机立即绑定
课程 \ C#开发轻松入门

C#开发轻松入门

2-10 C#的类型转换
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double d = 2.5;
int x = (int)d + 1;
Console.WriteLine(x);
}
}
}
2019-01-31 查看完整代码
2-9 C#的数据类型
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string name = "曹少钦";//姓名,string类型
char sex = '男';//性别,char类型
int age = 19;//年龄,int类型
double height = 1.72;//身高,double类型
Console.WriteLine("我叫{0},是{1}生,今年{2}岁,身高{3}米。",name,sex,age,height);
}
}
}
2019-01-31 查看完整代码
2-8 编程练习
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string today;//今天的午饭
string tomorrow;//明天的午饭
today = "鱼香肉丝";
tomorrow = "小鸡炖蘑菇";
//请在这里补充代码,实现变量today和tomorrow的交换
string temp;
temp = today;
today = tomorrow;
tomorrow = temp;



//打印
Console.WriteLine("我今天吃{0},明天吃{1}。",today,tomorrow);
}
}
}
2019-01-31 查看完整代码
2-7 算法——交换
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string boy = "秀丽";//男孩名字
string girl = "伟强";//女孩名字
string temp;//中间变量
temp = boy;//把男孩的名字赋值给temp
boy = girl;//把女孩的名字赋值给男孩
girl = temp;//把temp中的名字赋值给女孩
Console.WriteLine("男孩叫"+boy+" 女孩叫"+girl);
}
}
}
2019-01-31 查看完整代码
2-5 C#的变量
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
string hobby; //声明变量保存爱好
hobby = "剑道"; //给爱好变量赋值
Console.WriteLine("我爱好"+hobby);//打印变量
}
}
}
2019-01-31 查看完整代码
2-4 C#的常量
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
const string CITY = "布宜诺斯艾利斯";//常量,城市
const string NAME = "列奥波尔多·福图纳托·加尔铁里·卡斯特利";//常量,姓名
Console.WriteLine(NAME+"出生在"+CITY+"的一个工人家庭");//使用常量
}
}
}
2019-01-31 查看完整代码
2-2 C#的注释
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
/*
* 这是一段提示信息
*/
Console.WriteLine("积跬步,至千里");//打印并换行
}
}
}
2019-01-31 查看完整代码
2-1 C#中的关键字
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(String[]args)
{
Console.WriteLine("今日事,今日毕。");
}
}
}
2019-01-31 查看完整代码
首页上一页123下一页尾页
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号