1、注释符 1)、注销 2)、解释
2、c#的3种注释符 1)、单行注释 // 2)、多行注释 /要注释的内容/ 3)、文档注释 /// 多用来解释类或者方法
3、变量 用来在计算机当中存储数据。
存储整数100 数据类型:整数 在内存中开辟的空间应该是整数类型 int
存储变量的语法: 变量类型 变量名; 变量名=值;
"="号:在这并不表示等于的意思,而是赋值的意思,表示把等号右边的值赋值给等号左边的变量。
声明并且给变量赋值的简写形式: 变量类型 变量名=值;
4、数据类型 1)、整数类型:int 只能存储整数,不能存储小数。 2)、小数类型:double 既能存储整数,也能存储小数,小数点后面的位数 15~16位。 3)、金钱类型:decimal:用来存储金钱,值后面需要加上一个m. 4)、字符串类型:string,用来存储多个文本,也可以存储空,字符串类型的值需要被 双引号引来, 这个双引号必须是英文半角状态下的双引号 5)、字符类型:char,用来存储单个字符,最多、最少只能有一个字符,不能存储空。 字符类型的值需要用 单引号因起来。英文半角状态下的单引号。
5、波浪线 1)、如果你的代码中出现了红色的波浪线,意味着你的代码中出现了 语法错误。 2)、如果你的代码中出现了绿色的波浪线,说明你的代码语法并没有错误, 只不过提示你有可能会出现错误,但是不一定会出现错误。警告线
6、变量的使用规则 如果你要是用变量的话,应该要先声明再赋值再使用。
7、命名规则: ****首先要保证的就是这个变量的名字要有意义。 1 现阶段给变量起名字的时候都以字母开头 2 后面可以跟任意“字母”、数字、下划线. 注意: 1)你起的变量名不要与c#系统中的关键字重复. 2)在c#中,大小写是敏感的. HTML 3)同一个变量名不允许重复定义(先这么认为,不严谨)
给变量起名字的时候要满足两个命名规范: 1、Camel 骆驼命名规范。要求变量名首单词的首字母要小写,其余每个单词的首字母要大写。 多用于给变量命名。 2、Pascal 命名规范:要求每个单词的首字母都要大写,其余字母小写。多用于给类或者方法命名。 HighSchoolStudent
highSchoolStudent
8、赋值运算符 =:表示赋值的意思,表示把等号右边的值,赋值给等号左边的变量。 由等号连接的表达式称之为赋值表达式。 注意:每个表达式我们都可以求解除一个定值,对于赋值表达式而言,等号左边的变量的值, 就是整个赋值表达式的值。 int number=10;
9、+号的作用 1)、连接:当+号两边有一边是字符串的时候,+号就起到连接的作用。 2)、相加:两边是数字的时候
10、占位符 使用方法:先挖个坑,再填个坑。 使用占位符需要注意的地方: 1、你挖了几个坑,就应该填几个坑,如果你多填了,没效果。 如果你少填了,抛异常。 2、输出顺序:按照挖坑的顺序输出。 11、异常 异常是指:语法上并没有任何错误,只不过在程序运行的期间,由于某些原因出现了问题, 使程序不能再正常的运行。
12、转义符 转义符指的就是一个''+一个特殊的字符,组成了一个具有特殊意义的字符。 \n:表示换行 ":表示一个英文半角的双引号 \t:表示一个tab键的空格 \b:表示一个退格键,放到字符串的两边没有效果。 \r\n:windows操作系统不认识\n,只认识\r\n \:表示一个\
@符号 1、取消\在字符串中的转义作用,使其单纯的表示为一个'' 2、将字符串按照编辑的原格式输出
13、算数运算符 + - * / %
14、类型转换 隐式类型转换: 我们要求等号两遍参与运算的操作数的类型必须一致,如果不一致,满足下列条件会发生 自动类型转换,或者称之为隐式类型转换。 两种类型兼容 例如:int 和 double 兼容(都是数字类型) 目标类型大于源类型 例如:double > int 小的转大的
显示类型转换: 1、两种类型相兼容 int--double 2、大的转成小的 double----int 语法: (待转换的类型)要转换的值;
总结: 自动类型转换:int---->double 显示类型转换:double--->int
01注释符的使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _01注释符的使用
{
class Program
{
static void Main(string[] args)
{
//这行代码的作用是将Hello World打印到控制台当中
// Console.WriteLine("Hello World");
//这行代码的作用是暂停当前这个程序
// Console.ReadKey();
/*
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");*/
}
/// <summary>
/// 这个方法的作用就是求两个整数之间的最大值
/// </summary>
/// <param name="n1">第一个整数</param>
/// <param name="n2">第二个整数</param>
/// <returns>返回比较大的那个数字</returns>
public static int GetMax(int n1, int n2)
{
return n1 > n2 ? n1 : n2;
}
}
/// <summary>
/// 这个类用来描述一个人的信息 从 姓名 性别 年龄描述
/// </summary>
public class Person
{
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
public char Gender
{
get;
set;
}
}
}
02VS当中的常用快捷键
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _02VS当中的常用快捷键
{
class Program
{
static void Main(string[] args)
{
#region 这些代码实现了XX功能
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
Console.WriteLine("fdsfdsf");
#endregion
}
}
}
03、变量
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _03_变量
{
class Program
{
static void Main(string[] args)
{
//变量类型 变量名;
// 变量名 = 值;
//100
////官方语言:声明或者定义了一个int类型的变量
//int number;//在内存中开辟了一块能够存储整数的空间
////官方语言:给这个变量进行赋值
//number = 100;//表示把100存储到了这块空间内
//int n = 3.14;
// double d = 3;
//张三 李四 王五 赵六 abcdefg
//string zsName = "张三";
//string s="";//字符串可以存储 空
////字符串 字符 羊肉串和羊肉
//char gender = '男女';
// char c='';
//decimal money = 5000m;
double d = 36.6;
Console.WriteLine(d);
Console.ReadKey();
}
}
}
04变量的使用规则
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _04变量的使用规则
{
class Program
{
static void Main(string[] args)
{
int number;//声明或者定义了整数类型的变量
number = 20;
// Console.WriteLine(number);
Console.ReadKey();
// String s = "颤三";
string ss = "李四";
}
}
}
05变量的命名规范
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _05变量的命名规范
{
class Program
{
static void Main(string[] args)
{
//int number_1 = 10;
//int number_2 = 20;
//int number = 10;
//int Number = 10;
int number;
// int number = 10;
// int string=10;
//int a = 10;
//int b = 20;
}
}
}
06赋值运算符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _06赋值运算符
{
class Program
{
static void Main(string[] args)
{
int n = 10;
n = 50;//重新赋值,一旦给一个变量重新赋值,那么老值就不存在了,取而代之的新值。
Console.WriteLine(n);
Console.ReadKey();
}
}
}
07+号的使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _07_号的使用
{
class Program
{
static void Main(string[] args)
{
//string name = "王五";
//Console.WriteLine("你好,"+name);
Console.WriteLine(5 + "5");
Console.ReadKey();
}
}
}
08两个练习
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _08两个练习
{
class Program
{
static void Main(string[] args)
{
//有个叫卡卡西的人在旅店登记的时候前台让他填一张表,
//这张表的里的内容要存到电脑上,
//有姓名、年龄、邮箱、家庭住址,工资.
//之后把这些信息显示出来
//string name = "卡卡西";
//int age = 30;
//string email = "kakaxi@qq.com";
//string address = "火影村";
//decimal salary = 5000m;
//Console.WriteLine("我叫{0},我今年{1}岁了,我住在{2},我的邮箱是{3},我的工资是{4}", name, age, address, email, salary);
//Console.WriteLine("我叫" + name + ",我住在" + address + ",我今年" + age + "岁了" + ",我的邮箱是" + email + ",我的工资是" + salary);
//Console.ReadKey();
//int age = 18;
//age = 81;
//Console.WriteLine("原来你都" + age + "岁了呀");
//Console.ReadKey();
//3.定义四个变量,分别存储一个人的姓名、性别(Gender)、年龄、电话
//(TelephoneNumber)。然后打印在屏幕上 (我叫X,我今年 X岁了,我是X生,
//我的电话是XX)(电话号用什么类型,如:010-12345)
string name = "张三";
char gender = '男';
int age = 18;
string tel = "12345678900";
Console.WriteLine("我叫{0},我今年{1}岁了,我是{2}生,我的电话是{3}", name, age, gender, tel);
Console.ReadKey();
}
}
}
09复习
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _09复习
{
class Program
{
static void Main(string[] args)
{
/*
变量:存储数据
* 赋值运算符
* 数据类型:
* int 整数
* double decimal string char
* 命名规范
* Camel:
* Pascal
* 注释:
* //
*
///
* +号
*/
}
}
}
10占位符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _09下午复习
{
class Program
{
static void Main(string[] args)
{
/*
变量:存储数据
* 赋值运算符
* 数据类型:
* int 整数
* double decimal string char
* 命名规范
* Camel:
* Pascal
* 注释:
* //
*
///
* +号
*/
}
}
}
11交换变量
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _11交换变量
{
class Program
{
static void Main(string[] args)
{
//int n1 = 10;
//int n2 = 20;
//int temp = n1;
//n1 = n2;
//n2 = temp;
//Console.WriteLine("交换后,n1的值是{0},n2的值是{1}", n1, n2);
//Console.ReadKey();
//请交换两个int类型的变量,要求:不使用第三方的变量
int n1 = 50;
int n2 = 30;
//n1=20 n2=10;
n1 = n1 - n2;//n1=-10 n2=20
n2 = n1 + n2;//n1=-10 n2=10
n1 = n2 - n1;
Console.WriteLine("交换后,n1的值是{0},n2的值是{1}", n1, n2);
Console.ReadKey();
}
}
}
12接收用户的输入
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _12接收用户的输入
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("请输入你的姓名");
////我们还想要接收你输入的姓名
////接收用户在控制台的输入 11 3.14 男 张三
//string name = Console.ReadLine();
//Console.WriteLine("您的姓名是{0}", name);
//Console.ReadKey();
//1.练习:问用户喜欢吃什么水果(fruits),假如用户输入”苹果”,则显示”哈哈,这么巧,我也喜欢吃苹果”
//Console.WriteLine("美女,你喜欢吃啥子水果哟~~~~");
//string fruit = Console.ReadLine();
//Console.WriteLine("这么巧呀,我也喜欢吃{0}", fruit);
//Console.ReadKey();
//2.练习:请用户输入姓名性别年龄,当用户按下某个键子后在屏幕上显示:您好:XX您的年龄是XX是个X生
//Console.WriteLine("请输入您的姓名");
//string name = Console.ReadLine();
//Console.WriteLine("请输入您的年龄");
//string age = Console.ReadLine();
//Console.WriteLine("请输入您的性别");
//string gender = Console.ReadLine();
//Console.WriteLine("{0}你的年龄是{1}是个{2}生",name,age,gender);
//Console.ReadKey();
}
}
}
13、转移符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _13_转移符
{
class Program
{
static void Main(string[] args)
{
// Console.WriteLine("今天天气好晴\n朗处处好风光");
//Console.WriteLine("我想在这句话中输出一\"\"个英文半角的双引号");
//string name1 = "张三";
//string name2 = "李思思";
//string name3 = "王小五";
//string name4 = "李";
//Console.WriteLine("{0}\t{1}", name1, name2);
//Console.WriteLine("{0}\t{1}", name3, name4);
//Console.ReadKey();
//string str = "今天天气好晴\r\n朗处处好风光";
//System.IO.File.WriteAllText(@"C:\Users\SpringRain\Desktop\1111.txt", str);
//Console.WriteLine("写入成功!!!");
//Console.ReadKey();
//char c = '\b';//\ 在里面起到了一个转义的作用
//char cc='bb';
//Console.WriteLine(path);
//Console.ReadKey();
Console.WriteLine(@"今天天气好晴
朗处处好风光");
Console.ReadKey();
}
}
}
14、算数运算符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _14_算数运算符
{
class Program
{
static void Main(string[] args)
{
//int n1 = 10;
//int n2 = 3;
//int result = n1 / n2;
////Console.WriteLine(result);
////Console.ReadKey();
////演示:某学生三门课成绩为,语文:90 数学:80 英语:67,编程求总分和平均分.
//int chinese = 90;
//int math = 80;
//int english = 67;
//Console.WriteLine("总成绩是{0},平均成绩是{1}", chinese + math + english, (chinese + math + english) / 3);
//Console.ReadKey();
//练习2:计算半径为5的圆的面积和周长并打印出来.(pi为3.14)面积:pi*r*r; Perimeter(周长)
//=号两遍的数据类型必须一样
//int r = 5;
//double area = 3.14 * r * r;
//double perimeter = 2 * 3.14 * r;
//Console.WriteLine("圆的面积是{0},周长是{1}", area, perimeter);
//Console.ReadKey();
//练习3:某商店T恤(T-shirt)的价格为35元/件,
//裤子(trousers)的价格为120元/条.小明在该店买了3件T恤和2条裤子,
//请计算并显示小明应该付多少钱?
//int T_shirt = 35;
//int trousers = 120;
//int totalMoney = 3 * T_shirt + 2 * trousers;
//Console.WriteLine(totalMoney);
//double realMoney = totalMoney * 0.88;
//Console.WriteLine(realMoney);
//Console.ReadKey();
////打8.8折后呢?
//int number = 10;
//int---double
//double d = number;//自动类型转换 隐式类型转换 int--double
//double d = 303.6;
////语法:
////(待转换的类型)要转换的值;
////double----int//强制类型转换 显示类型转换
//int n = (int)d;
//Console.WriteLine(n);
//Console.ReadKey();
}
}
}
15、类型转换
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _15_类型转换
{
class Program
{
static void Main(string[] args)
{
int n1 = 10;
int n2 = 3;
double d = n1*1.0 / n2;
Console.WriteLine("{0:0.0000}",d);
Console.ReadKey();
////int n1 = 5;
//double n1 = 5;
//int n2 = 2;
//double d = n1 / n2;
//Console.WriteLine(d);
//Console.ReadKey();
}
}
}