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

C#开发轻松入门

3-1 C#用流程图描述程序逻辑
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double x = 13.9, y = 24.4;
double sum = x + y;
double avg=sum/2;
Console.WriteLine(avg);
}
}
}
2021-02-10 查看完整代码
2-22 C#的运算符优先级
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x=1;
bool a = ++x * x > 3;
bool b = true;//请赋值
Console.WriteLine(a==b);
}
}
}
2021-02-10 查看完整代码
2-21 C#的赋值运算符
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double x, y;
x = y = 2;//从右向左赋值,x、y的值都是2
x /= 0.5;
y %= 2;
Console.WriteLine(x-y);
}
}
}
2021-02-10 查看完整代码
2-19 C#的逻辑运算符(二)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int age = 4;//年龄
if (age < 6 || age > 60)
Console.WriteLine("请坐爱心座!");
else
Console.WriteLine("请坚持一下!");
}
}
}
2021-02-10 查看完整代码
2-18 C#的逻辑运算符(一)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(true||false);//输出True
Console.WriteLine(true&&false);//输出False
Console.WriteLine(!false);//输出True
}
}
}
2021-02-10 查看完整代码
2-17 C#的比较运算符
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double x = 3.5;
int y = 3;
Console.WriteLine((int)x>=y);
}
}
}
2021-02-10 查看完整代码
2-15 C#的算术运算符(三)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int x = 5;
int y = 5;
int z = 5;
x++;
Console.Write(x);
Console.Write(y+1);
Console.Write(++z);
}
}
}
2021-02-10 查看完整代码
2-14 C#的算术运算符(二)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int year = 2015;//年份
Console.WriteLine(year%4);//求年份除以4的余数
}
}
}
2021-02-10 查看完整代码
2-13 C#的算术运算符(一)
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
double salary = 6000.00;//基本工资
double prize = 3200.00;//奖金
double tax = 4500.00;//交税
Console.Write("我的工资奖金总额是{0}元",salary+prize);
Console.Write("我的税后收入是{0}元",salary+ prize-tax);
}
}
}
2021-02-10 查看完整代码
2-11 C#标识符的命名规则
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{
int _num1 = 5;//第一个加数
int _num2 = 7;//第二个加数
int sum=_num1+_num2;//求和
Console.WriteLine("和是{0}",sum);//打印结果
}
}
}
2021-02-10 查看完整代码
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);
}
}
}
2021-02-10 查看完整代码
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);
}
}
}
2021-02-10 查看完整代码
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 = today;
today = tomorrow;
tomorrow = temp;






//打印
Console.WriteLine("我今天吃{0},明天吃{1}。",today,tomorrow);
}
}
}
2021-02-10 查看完整代码
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);
}
}
}
2021-02-10 查看完整代码
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);//打印变量
}
}
}
2021-02-10 查看完整代码
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+"的一个工人家庭");//使用常量
}
}
}
2021-02-10 查看完整代码
2-2 C#的注释
using System;
using System.Collections.Generic;
using System.Text;

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

namespace Test
{
class Program
{
static void Main(String[]args)
{
Console.WriteLine("今日事,今日毕。");
}
}
}
2021-02-10 查看完整代码
意见反馈 帮助中心 APP下载
官方微信