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

你可能感兴趣的文章
NFS远程目录挂载
查看>>
nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
查看>>
NFV商用可行新华三vBRAS方案实践验证
查看>>
ng build --aot --prod生成文件报错
查看>>
ng 指令的自定义、使用
查看>>
ng6.1 新特性:滚回到之前的位置
查看>>
nghttp3使用指南
查看>>
【Flink】Flink 2023 Flink 自动化运维的大规模落地实践
查看>>
Nginx
查看>>
nginx + etcd 动态负载均衡实践(一)—— 组件介绍
查看>>
nginx + etcd 动态负载均衡实践(三)—— 基于nginx-upsync-module实现
查看>>
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + Tomcat + SpringBoot 部署项目
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>
Nginx - Header详解
查看>>
nginx - thinkphp 如何实现url的rewrite
查看>>
Nginx - 反向代理、负载均衡、动静分离、底层原理(案例实战分析)
查看>>
Nginx - 反向代理与负载均衡
查看>>