博客
关于我
夜光带你走进C# 游戏开发等(五十二)擅长的领域
阅读量:311 次
发布时间:2019-03-01

本文共 13866 字,大约阅读时间需要 46 分钟。

夜光序言:

 

废铁之所以能成为有用的钢,是因为它经得起痛苦的磨炼。

 

 

 

 

 

 

 

 

 

正文:

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp3{    class Program    {        ///         /// 夜光:写一个方法AddOne,该方法传入一个整数n,要求对该数+1,并且不通过返回值返回结果        ///         ///         static void AddOne(int n)        {            n++;        }        static void Main(string[] args)        {            int m = 3;            AddOne(m); // m+1            Console.WriteLine(m);  //4            Console.ReadLine();        }    }}

 

 

 

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp3{    class Program    {        ///         /// 夜光:写一个方法AddOne,该方法传入一个整数n,要求对该数+1,并且不通过返回值返回结果        ///         ///         static void AddOne(ref int n)        {            n++;  // *(1001)++   如果C语言学的比较好,对指针有较深理解,就很好            Console.WriteLine(n);        }        static void Swap(ref int a,ref int b)        {            int c = a;            a = b;            b = c;        }        static void Main(string[] args)        {            int m, n;            m = 3;            n = 5;            Swap(ref m ,ref n);            Console.WriteLine("m={0},n={1}", m, n);            /*int m = 3;            AddOne(m); // m+1            Console.WriteLine(m);  //4            Console.ReadLine();*/            Console.ReadLine();        }    }}

 

 

 

 

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 功能封装{    class Program    {        ///         ///         ///         /// 
static int[] Input() { Console.WriteLine("请输入数组长度:"); int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; for(int i = 0; i < a.Length; i++) { Console.WriteLine("第{0}个元素", i); a[i] = int.Parse(Console.ReadLine()); } return a; } /// /// /// /// static void Output(int[] a) { Console.WriteLine("----------------------------"); for (int i = 0; i< a.Length; i++) { Console.WriteLine("a[{0}] = {1}", i, a[i]); } } /// /// /// /// ///
static int Sum(int[] a) { int s = 0; for (int i = 0; i < a.Length; i++) { s += a[i]; } /* Console.WriteLine("元素之和为:{0}",s);*/ return s; } static void Main(string[] args) { int[] b = Input(); Output(b); int n = Sum(b); Console.WriteLine("元素之和为:{0}", n); Console.ReadLine(); } }}

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 功能封装{    class Program    {        ///         ///         ///         /// 
static int[] Input() { Console.WriteLine("请输入数组长度:"); int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; for(int i = 0; i < a.Length; i++) { Console.WriteLine("第{0}个元素", i); a[i] = int.Parse(Console.ReadLine()); } return a; } /// /// /// /// static void Output(int[] a) { Console.WriteLine("----------------------------"); for (int i = 0; i< a.Length; i++) { Console.WriteLine("a[{0}] = {1}", i, a[i]); } } /// /// /// /// ///
static int Sum(int[] a) { int s = 0; for (int i = 0; i < a.Length; i++) { s += a[i]; } /* Console.WriteLine("元素之和为:{0}",s);*/ return s; } /// /// /// /// ///
static string Merge(string[] sa) { string m = ""; for(int i = 0; i < sa.Length; i++) { m += sa[i]; } return m; } static void Main(string[] args) { int[] b = Input(); Output(b); int n = Sum(b); Console.WriteLine("元素之和为:{0}", n); string m = Merge(new String[] {"China","Japan","Korea"}); Console.WriteLine(m); Console.ReadLine(); } }}

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 功能封装{    class Program    {        ///         /// 夜光:输入        ///         /// 
static int[] Input() { Console.WriteLine("请输入数组长度:"); int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; for(int i = 0; i < a.Length; i++) { Console.WriteLine("第{0}个元素", i); a[i] = int.Parse(Console.ReadLine()); } return a; } /// /// 夜光:输出 /// /// static void Output(int[] a) { Console.WriteLine("----------------------------"); for (int i = 0; i< a.Length; i++) { Console.WriteLine("a[{0}] = {1}", i, a[i]); } } /// /// /// /// ///
static int Sum(int[] a) { int s = 0; for (int i = 0; i < a.Length; i++) { s += a[i]; } /* Console.WriteLine("元素之和为:{0}",s);*/ return s; } /// /// 夜光:拼接字符串 /// /// ///
static string Merge(string[] sa) { string m = ""; for(int i = 0; i < sa.Length; i++) { m += sa[i]; } return m; } /// /// 夜光 /// ///
static void StringCount(string s,ref int zm,ref int sz,ref int ts) { zm = 0; sz = 0; ts = 0; for(int i = 0; i < s.Length; i++) { if (Char.IsLetter(s[i])) { zm++; } else if(Char.IsDigit(s[i])) { sz++; } else { ts++; } } } static void Main(string[] args) { /* int[] b = Input(); Output(b); int n = Sum(b); Console.WriteLine("元素之和为:{0}", n); string m = Merge(new String[] {"China","Japan","Korea"}); Console.WriteLine(m); */ int zm, sz, ts; sz = zm = ts = 0; StringCount("This is 123 test~~", ref zm, ref sz, ref ts); Console.WriteLine("ZM={0},SZ={1},TS={2}", zm, sz, ts); Console.ReadLine(); } }}

 

 

 

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 功能封装{    class Program    {        ///         /// 夜光:输入        ///         /// 
static int[] Input() { Console.WriteLine("请输入数组长度:"); int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; for(int i = 0; i < a.Length; i++) { Console.WriteLine("第{0}个元素", i); a[i] = int.Parse(Console.ReadLine()); } return a; } /// /// 夜光:输出 /// /// static void Output(int[] a) { Console.WriteLine("----------------------------"); for (int i = 0; i< a.Length; i++) { Console.WriteLine("a[{0}] = {1}", i, a[i]); } } /// /// /// /// ///
static int Sum(int[] a) { int s = 0; for (int i = 0; i < a.Length; i++) { s += a[i]; } /* Console.WriteLine("元素之和为:{0}",s);*/ return s; } /// /// 夜光:拼接字符串 /// /// ///
static string Merge(string[] sa) { string m = ""; for(int i = 0; i < sa.Length; i++) { m += sa[i]; } return m; } /// /// 夜光 /// ///
static void StringCount(string s,ref int zm,ref int sz,ref int ts) { zm = 0; sz = 0; ts = 0; for(int i = 0; i < s.Length; i++) { if (Char.IsLetter(s[i])) { zm++; } else if(Char.IsDigit(s[i])) { sz++; } else { ts++; } } } /// /// 写一个循环,夜光:找出最大的数 /// /// ///
static int Max(int[] a) { int index = 0; //我们先定义一个下标 for(int i = 1; i < a.Length; i++) //从1开始,和那个最大的进行比较 { if(a[i] > a[index]) { index = i; } } return index; } static void Main(string[] args) { int index = Max(new int[] { 1, 3, 5, 7, 9 }); Console.WriteLine(index); /* int[] b = Input(); Output(b); int n = Sum(b); Console.WriteLine("元素之和为:{0}", n); string m = Merge(new String[] {"China","Japan","Korea"}); Console.WriteLine(m); *//* int zm, sz, ts; sz = zm = ts = 0; StringCount("This is 123 test~~", ref zm, ref sz, ref ts); Console.WriteLine("ZM={0},SZ={1},TS={2}", zm, sz, ts);*/ Console.ReadLine(); } }}

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 功能封装{    class Program    {        ///         /// 夜光:输入        ///         /// 
static int[] Input() { Console.WriteLine("请输入数组长度:"); int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; for(int i = 0; i < a.Length; i++) { Console.WriteLine("第{0}个元素", i); a[i] = int.Parse(Console.ReadLine()); } return a; } /// /// 夜光:输出 /// /// static void Output(int[] a) { Console.WriteLine("----------------------------"); for (int i = 0; i< a.Length; i++) { Console.WriteLine("a[{0}] = {1}", i, a[i]); } } /// /// /// /// ///
static int Sum(int[] a) { int s = 0; for (int i = 0; i < a.Length; i++) { s += a[i]; } /* Console.WriteLine("元素之和为:{0}",s);*/ return s; } /// /// 夜光:拼接字符串 /// /// ///
static string Merge(string[] sa) { string m = ""; for(int i = 0; i < sa.Length; i++) { m += sa[i]; } return m; } /// /// 夜光 /// ///
static void StringCount(string s,ref int zm,ref int sz,ref int ts) { zm = 0; sz = 0; ts = 0; for(int i = 0; i < s.Length; i++) { if (Char.IsLetter(s[i])) { zm++; } else if(Char.IsDigit(s[i])) { sz++; } else { ts++; } } } /// /// 写一个循环,夜光:找出最大的数 /// /// ///
static int Max(int[] a) { int index = 0; //我们先定义一个下标 for(int i = 1; i < a.Length; i++) //从1开始,和那个最大的进行比较 { if(a[i] > a[index]) { index = i; } } return index; } /// /// /// /// /// /// static void Max2D(int[,] a, ref int row,ref int col) { row = 0; col = 0; for(int i = 0; i < a.GetLength(0); i++) { for(int j = 0; j < a.GetLength(1); j++) { if (a[i, j] > a[row, col]) { row = i; col = j; } } } } static void Main(string[] args) { int row = 0; int col = 0; Max2D(new int[,]{ {1,2,3 }, {0,2,4 }, {9,7,3 } },ref row,ref col); Console.WriteLine("row={0},col={1}", row, col);/* int index = Max(new int[] { 1, 3, 5, 7, 9 }); Console.WriteLine(index);*/ /* int[] b = Input(); Output(b); int n = Sum(b); Console.WriteLine("元素之和为:{0}", n); string m = Merge(new String[] {"China","Japan","Korea"}); Console.WriteLine(m); *//* int zm, sz, ts; sz = zm = ts = 0; StringCount("This is 123 test~~", ref zm, ref sz, ref ts); Console.WriteLine("ZM={0},SZ={1},TS={2}", zm, sz, ts);*/ Console.ReadLine(); } }}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载地址:http://mefo.baihongyu.com/

你可能感兴趣的文章
Mysql 整形列的字节与存储范围
查看>>
mysql 断电数据损坏,无法启动
查看>>
MySQL 日期时间类型的选择
查看>>
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度)
查看>>
MySQL 是如何加锁的?
查看>>
MySQL 是怎样运行的 - InnoDB数据页结构
查看>>
mysql 更新子表_mysql 在update中实现子查询的方式
查看>>
MySQL 有什么优点?
查看>>
mysql 权限整理记录
查看>>
mysql 权限登录问题:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
查看>>
MYSQL 查看最大连接数和修改最大连接数
查看>>
MySQL 查看有哪些表
查看>>
mysql 查看锁_阿里/美团/字节面试官必问的Mysql锁机制,你真的明白吗
查看>>
MySql 查询以逗号分隔的字符串的方法(正则)
查看>>
MySQL 查询优化:提速查询效率的13大秘籍(避免使用SELECT 、分页查询的优化、合理使用连接、子查询的优化)(上)
查看>>
mysql 查询数据库所有表的字段信息
查看>>
【Java基础】什么是面向对象?
查看>>
mysql 查询,正数降序排序,负数升序排序
查看>>
MySQL 树形结构 根据指定节点 获取其下属的所有子节点(包含路径上的枝干节点和叶子节点)...
查看>>
mysql 死锁 Deadlock found when trying to get lock; try restarting transaction
查看>>