博客
关于我
夜光带你走进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 通过查看mysql 配置参数、状态来优化你的mysql
查看>>
mysql 里对root及普通用户赋权及更改密码的一些命令
查看>>
Mysql 重置自增列的开始序号
查看>>
mysql 锁机制 mvcc_Mysql性能优化-事务、锁和MVCC
查看>>
MySQL 错误
查看>>
mysql 随机数 rand使用
查看>>
MySQL 面试题汇总
查看>>
MySQL 面试,必须掌握的 8 大核心点
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>
MySQL-Buffer的应用
查看>>
mysql-cluster 安装篇(1)---简介
查看>>
mysql-connector-java.jar乱码,最新版mysql-connector-java-8.0.15.jar,如何愉快的进行JDBC操作...
查看>>