using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
//单行注释
/* 多行注释符
*/
///文档注释/段注释
/*
C#强类型 面向对象(封装、继承、多态)
封装:调用方便
继承:
多态:
大驼峰命名法:每个单词的首字母用大写
小驼峰命名法:第一个个单词的首字母用小写其余的是大写(系统关键字为此类颜色为蓝色)
下划线命名法:每个单词间用下划线分割
访问修饰符:internal 内部的
public 公共的
private 私有的
protected 受保护的
class :类
声明一个类:1.写的位置
2.访问修饰符 class 类名{}
static:静态的 修饰符
void:空 返回值类型
声明一个方法:1.位置
2.修饰符 返回值类型 方法名(参数){代码/变量}
<>:<数据类型>
.cs:项目入口点
*/
namespace _20260414shiting
{
internal class Program
{
static void Main(string[] args)//方法 主方法 主程序入口
{
}
static void 类型()
{
/*值类型、引用类型
byte 字节 无符号 8bit 1Byte
sbyte
short 短整型 有符号 16bit 4Byte
ushort
int 整型 有符号 32bit 4Byte
uint 无符号整型
long 长整型 有符号 64bit 8Byte
ulong
double 双精度浮点型 有符号 64bit
float(single) 单精度浮点型 32bit
decimal 十进制浮点型 128bit
共同点:1.都能存整数
2.都有符号
不同点:1.1默认为double
bool 布尔类型 true/false
char 字符类型 1.必须用‘’表示
2.‘’有且只有一个值
string 字符串 1.必须用“”表示
2.“”空字符串占一个空字符串的空间
*/
}
static void 类型转换()
{
/*
隐式转换(符合代码逻辑)、显示转换
强制转换 Convert、Parse、TryParse
*/
string e = "1";
int f = Convert.ToInt32(e);
int g = int.Parse(e);//适用于已知情况
int.TryParse(e, out int x);
Console.WriteLine(e);//换行的输出
Console.Write(e);
Console.Read();//输入语句
Console.ReadLine();//输入并换行
Console.ReadKey();//是否显示输入内容
}
static int 返回值()
{
return 0;
}
static void 单双分支()
{
/*使用return来消除多分支和嵌套
单分支
if (判断条件)
{
}
双分支
if(){
}
else
{
}
*/
Console.WriteLine("请输入女方年龄,单位:年");
if (!uint.TryParse(Console.ReadLine(), out uint gy))
{
Console.WriteLine("输入错误,需要输入女方的年龄");
return;
}
if (gy > 18)
{
Console.WriteLine("合适");
return;
}
if (gy < 18)
{
Console.WriteLine("不合适");
return;
}
}
static void 多分支()
{
Console.WriteLine();
if (!uint.TryParse(Console.ReadLine(), out uint tz))
{
Console.WriteLine("请输入非负整数");
return;
}
else if (tz >= 160)
{
Console.WriteLine("不合适");
}
else if (tz < 160 && tz >= 130)
{
Console.WriteLine("微胖");
}
else if (tz < 130 && tz >= 100)
{
Console.WriteLine("合适");
}
else if (tz < 100)
{
Console.WriteLine("微瘦");
}
}
static void 分支嵌套()
{
/**/
Console.WriteLine("女方长相是否符合审美,请输入是或否");
char zx= char.Parse(Console.ReadLine());
if (zx =='否')
{
Console.WriteLine("拜拜");
return;
}
Console.WriteLine("女方有几套房");
uint fc = uint.Parse(Console.ReadLine());
if (fc<5)
{
Console.WriteLine("继续努力");
}
else if (fc>10)
{
Console.WriteLine("微信上聊");
return;
}
Console.WriteLine("是不是独生女");
if (bool.TryParse(Console.ReadLine(), out bool r))
{
if (r) {
Console.WriteLine("请你吃个饭");
return;
}
}
Console.WriteLine("女方年薪,单位万");
double nx = double.Parse(Console.ReadLine());
if(nx>=500){
Console.WriteLine("我对你一见钟情");
return;
}
else if(nx<100)
{
Console.WriteLine("我陪你逛街");
return;
}
Console.WriteLine("女方学历");
string xl = Console.ReadLine();
if (xl == "博士")
{
Console.WriteLine("我们合适");
}
else if (xl=="硕士")
{
Console.WriteLine("先处着");
}
else if (xl == "学士")
{
Console.WriteLine("学士好啊");
}
else if (xl == "其他")
{
Console.WriteLine("也不错");
}
}
static void 简易计算器()
{
/*
1.用户输入第一个数 提示 double
2.用户输入运算符 判定 指定运算符 + - * / % || ^ 2 √ lg ln ~
2.1 在这里判断|| 2 √ lg ln ~
3.用户输入第二个数
3.1 在这里判断 + - * / %
4.输出
4.1 拼接
double num1=1;
double num2=2;
double num3=num1+num2;
Console.WriteLine($"两数相加的结果为:{num3}");
Console.WriteLine($"两数相加的结果为;"+ num3);
Console.WriteLine($"两数相加的结果为:{}", num3);
Math.Abs()
*/
Console.WriteLine("请输入第一个数字");
if( !double.TryParse(Console.ReadLine(),out double a))
{
Console.WriteLine("请输入数字");
return;
}
Console.WriteLine("请输入你需要的运算符");
string x = Console.ReadLine();
if (!(x=="+"||x=="-"||x=="*" || x == "/"||x == "%"|| x == "||" || x == "2" || x == "√" || x == "lg" || x == "ln"))
{
Console.WriteLine("请输入正确的的运算符");
return;
}
if (x == "||" || x == "2" || x == "√" || x == "lg" || x == "ln")
{
if (x=="||")
{
if (a < 0)
{
double y = -a;
Console.WriteLine(a+"的绝对值为:" +y);
}
else { Console.WriteLine(a+"的绝对值为:" + a);
return;
}
}
if (x == "2")
{
double y = a * a;
Console.WriteLine(a+"的平方为:" + y);
return;
}
if (x== "√")
{
double y = Math.Sqrt(a);
Console.WriteLine(a+"的平方根为"+y);
return;
}
if (x == "lg")
{
if (a == 0)
{
Console.WriteLine("数字不能为0");
return;
}
else {
double y = Math.Log10(a);
Console.WriteLine("lg" + a + "的运算结果为" + y);
return;
}
}
if (x == "ln")
{
if (a == 0)
{
Console.WriteLine("数字不能为0");
return;
}
else
{
double y = Math.Log(a);
Console.WriteLine("ln" + a + "的运算结果为" + y);
return;
}
}
}
Console.WriteLine("请输入第二位数");
if (!double.TryParse(Console.ReadLine(), out double z))
{
Console.WriteLine("请输入数字");
}
if (x == "+")
{
double y = a + z;
Console.WriteLine("两数之和为:" + y);
return;
}
if (x == "-")
{
double y = a - z;
Console.WriteLine(a+"-"+z+"的运算结果为:"+y);
return;
}
if(x == "*")
{
double y = a*z;
Console.WriteLine(a + "*" + z + "的运算结果为:" + y);
return;
}
if (x == "/")
{
if (z != 0)
{
double y = a / z;
Console.WriteLine(a + "除" + z + "的运算结果为:" + y);
return;
}
else
{
Console.WriteLine("除数不能为0");
return;
}
}
if (x == "%")
{
if (z != 0)
{
double y = a%z;
Console.WriteLine(a + "对" + z + "取余的运算结果为:" + y);
return;
}
else
{
Console.WriteLine("除数不能为0");
return;
}
}
}
}
}
2253



被折叠的 条评论
为什么被折叠?



