net学习源码.docx_第1页
net学习源码.docx_第2页
net学习源码.docx_第3页
net学习源码.docx_第4页
net学习源码.docx_第5页
已阅读5页,还剩44页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

.net学习源码第二天,基础语法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);*/ / / 这个方法的作用就是求两个整数之间的最大值 / / 第一个整数 / 第二个整数 / 返回比较大的那个数字 public static int GetMax(int n1, int n2) return n1 n2 ? n1 : n2; / / 这个类用来描述一个人的信息 从 姓名 性别 年龄描述 / public class Person public string Name get; set; public int Age get; set; public char Gender get; set; namespace _02S当中的常用快捷键 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); #endregion 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(); namespace _04变量的使用规则 class Program static void Main(string args) int number;/声明或者定义了整数类型的变量 number = 20; / Console.WriteLine(number); Console.ReadKey(); / String s = 颤三; string ss = 李四; 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; namespace _06赋值运算符 class Program static void Main(string args) int n = 10; n = 50;/重新赋值,一旦给一个变量重新赋值,那么老值就不存在了,取而代之的新值。 Console.WriteLine(n); Console.ReadKey(); namespace _07_号的使用 class Program static void Main(string args) /string name = 王五; /Console.WriteLine(你好,+name); Console.WriteLine(5 + 5); Console.ReadKey(); namespace _08两个练习 class Program static void Main(string args) /有个叫卡卡西的人在旅店登记的时候前台让他填一张表, /这张表的里的内容要存到电脑上, /有姓名、年龄、邮箱、家庭住址,工资. /之后把这些信息显示出来 /string name = 卡卡西; /int age = 30; /string email = ; /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(); namespace _09下午复习 class Program static void Main(string args) /* 变量:存储数据 * 赋值运算符 * 数据类型: * int 整数 * double decimal string char * 命名规范 * Camel: * Pascal * 注释: * / * / * +号 */ namespace _10占位符 class Program static void Main(string args) int n1 = 10; int n2 = 20; int n3 = 30; Console.WriteLine(第一个数字是1,第二个数字是0,第三个数字是2, n1, n2,n3); Console.WriteLine(第一个数字是: + n1 + ,第二个数字是: + n2 + ,第三个数字是: + n3); Console.ReadKey(); 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(); 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(); namespace _13_转义符 class Program static void Main(string args) / Console.WriteLine(今天天气好晴n朗处处好风光); /Console.WriteLine(我想在这句话中输出一个英文半角的双引号); /string name1 = 张三; /string name2 = 李思思; /string name3 = 王小五; /string name4 = 李狗蛋; /Console.WriteLine(0t1, name1, name2); /Console.WriteLine(0t1, name3, name4); /Console.WriteLine(学习编b程有用b么?学了不一定会,会了不一定能找到工作,找到工作 不应能买的起房子,买的起房子不一定娶得起老婆,娶得起老婆不一定生的了孩子,生的了孩子不一定是你的b); /Console.ReadKey(); /string str = 今天天气好晴rn朗处处好风光; /System.IO.File.WriteAllText(C:UsersSpringRainDesktop1111.txt, str); /Console.WriteLine(写入成功!); /Console.ReadKey(); /char c = b;/ 在里面起到了一个转义的作用 /char cc=bb; /string path=F:老赵生活musicabcde小泽玛利亚.avi; /Console.WriteLine(path); /Console.ReadKey(); Console.WriteLine(今天天气好晴朗处处好风光); Console.ReadKey(); 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(); 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(); 第三天,运算符namespace _01复习 class Program static void Main(string args) /* 变量 * * 赋值运算符= int num=10; * 占位符 * 变量的命名规范 * Camel: * Pascal: * +号的使用: * 1、连接 * string s1=123; * int num=5; * s1+num num+100 * 2、相加 * 三种注释 * / * / * 快捷键 * 算数运算符 * +=*除% * 转义符 * / / /r/n /b /t * 1、取消在字符串中的转义作用 2、按原格式输出字符串 * 类型转换 * 1、强制类型转换 显示类型转换 * 2、自动类型转换 隐式类型转换 * * 类型兼容 double int * * */ /int num = 10; /double d = num;/自动 小的转大的 /double dd = 3.13; /int n = (int)dd; namespace _02_两道作业题 class Program static void Main(string args) /练习,编程实现计算几天(如46天)是几周零几 天. 6周零4天 /int days = 46; /int weeks = days / 7; /int day = days % 7; /Console.WriteLine(0天是1周零2天,days,weeks,day); /Console.ReadKey(); /编程实现107653秒是几天几小时几分钟几秒? / 60*60 3600 *24=86400 86400 int seconds = 107653; int days = seconds / 86400;/求得天数 int secs = seconds % 86400;/求得求完天数后剩余的秒数 int hours = secs / 3600;/求得小时数 secs = secs % 3600;/求得小时数后剩余的秒数 int mins = secs / 60;/求得分钟数 secs = secs % 60; Console.WriteLine(0秒是1天2小时3分钟4秒, seconds, days, hours, mins, secs); Console.ReadKey(); namespace _03类型转换 class Program static void Main(string args) /显示类型转换、自动类型转换 /int-double double -int /string s = 123abc; /将字符串转换成int或者double类型 /double d = Convert.ToDouble(s); /int n = Convert.ToInt32(s); /Console.WriteLine(n); /Console.WriteLine(d); /Console.ReadKey(); /让用户输入姓名 语文 数学 英语 三门课的成绩, /然后给用户显示:XX,你的总成绩为XX分,平均成绩为XX分。 Console.WriteLine(请输入你的姓名); string name = Console.ReadLine(); Console.WriteLine(请输入你的语文成绩); string strChinese = Console.ReadLine(); Console.WriteLine(请输入你的数学成绩); string strMath = Console.ReadLine(); Console.WriteLine(请输入你的英语成绩); string strEnglish = Console.ReadLine(); double chinese = Convert.ToDouble(strChinese); double math = Convert.ToDouble(strMath); double english = Convert.ToDouble(strEnglish); double sumScore = chinese + math + english; double avg = (int)sumScore*1.0 / 3; Console.WriteLine(0你的总成绩是1平均成绩是2:0.00, name, sumScore, avg); Console.ReadKey(); /55 77 88 557788 /由于字符串去相加的话,最终会变成相连接,如果要拿字符串类型的变量参与计算 /需要将字符串转换成int或者double类型 /int chinese = Convert.ToInt32(strChinese); /int math = Convert.ToInt32(strMath); /int english = Convert.ToInt32(strEnglish); /Console.WriteLine(0你的总成绩是1,平均成绩是2, name, chinese + math + english, (chinese + math + english) / 3); /Console.ReadKey(); namespace _04Convert类型转换 class Program static void Main(string args) /提示用户输入一个数字 接收 并且向控制台打印用户输入的这个数字的2倍 Console.WriteLine(请输入一个数字); / string strNumber = Console.ReadLine(); /将用户输入的字符串转换成int或者double类型 double number = Convert.ToDouble(Console.ReadLine(); Console.WriteLine(number*2); Console.ReadKey(); namespace _05加加减减 class Program static void Main(string args) / int number = 10; / / number+; / +number;/number=number+1; / / number-; / -number; / Console.WriteLine(number); / Console.ReadKey(); / int number = 10; / int result = 10 + number+; / /int result = 10 + number; / /number+; / /int result = 10 + +number; / number+; / int result = 10 + number; / Console.WriteLine(number); / Console.WriteLine(result); / Console.ReadKey(); / int number = 10; / int result = 10 + number-; / /int result = 10 + number; / /number-; / / int result = 10 + -number; / number-; / int result = 10 + number; / Console.WriteLine(number); / Console.WriteLine(result); / Console.ReadKey(); / int a = 5; / a+; / +a; / -a; / a-; / int b = a+ + +a * 2 + -a + a+; / int b = a + a * 2 + a + a; / / 5+7*2+6+6 7 / Console.WriteLine(a); / Console.WriteLine(b); / Console.ReadKey(); /如果你有了一个喜欢的女生,你应该好好学习,努力上个好大学,毕业找个高新的工作。 /在你喜欢的女生结婚

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论