博客
关于我
夜光带你走进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/

你可能感兴趣的文章
MQ 重复消费如何解决?
查看>>
mqtt broker服务端
查看>>
MQTT 保留消息
查看>>
MQTT 持久会话与 Clean Session 详解
查看>>
MQTT工作笔记0007---剩余长度
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
Mqtt搭建代理服务器进行通信-浅析
查看>>
MS Edge浏览器“STATUS_INVALID_IMAGE_HASH“兼容性问题
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
MSBuild 教程(2)
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL数据库迁移到Oracle(二)
查看>>