本文共 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/