娉涘瀷鏂规硶
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了娉涘瀷鏂规硶相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/some' title='some'>some
++ items DPoS generics sharp ret div find1 namespace CSharp2._0 2 { 3 public class Finder 4 { 5 //娉涘瀷鏂规硶 6 public static int Find<T>(T[] items, T item) 7 { 8 for (int i = 0; i < items.Length; i++) 9 { 10 if (item.Equals(items[i])) 11 { 12 return i; 13 } 14 } 15 return -1; 16 } 17 } 18 //鑰﹀悎 19 class Program 20 { 21 22 string sss; 23 List<string> ss; 24 25 static void Main(string[] args) 26 { 27 NoGenericStatc nst = new NoGenericStatc(5); 28 nst.Push(1); 29 nst.Push(2); 30 nst.Push("浣犲ザ濂剁殑"); 31 nst.Push(3); 32 nst.Push("浣犲鐨?/span>"); 33 34 Console.WriteLine(nst.Pop()); 35 Console.WriteLine(nst.Pop()); 36 Console.WriteLine(nst.Pop()); 37 38 GenericStac<int> intstac = new GenericStac<int>(4); 39 intstac.Push(1); 40 //intstac.Push("abc"); 41 42 GenericStac<Goods> gss = new GenericStac<Goods>(10); 43 gss.Push(new Goods()); 44 45 //鍙互鍋氫竴涓鐢熺被锛岀劧鍚庢潵鏌ユ壘鏌愪釜鍚屽銆?/span> 46 string[] stuNames = new string[] {"abc","someone", "cba" }; 47 int index = Finder.Find<string>(stuNames, "someone"); 48 49 if (index > -1) 50 { 51 Console.WriteLine("someone鍦ㄦ暟缁勪腑鐨勪綅缃槸:{0}", index); 52 } 53 54 int[] ages = new int[] { 18, 17, 20, 69, 5 }; 55 56 int findNum = 89; 57 int indexB = Finder.Find<int>(ages, findNum); 58 59 if (indexB > -1) 60 { 61 Console.WriteLine("{0}鍦ㄦ暟缁勪腑鐨勪綅缃槸:{1}",findNum, index); 62 } 63 else 64 { 65 Console.WriteLine("{0}鍦ㄦ暟缁勫苟涓嶅瓨鍦?/span>", findNum); 66 } 67 68 string[] names = new string[] { "a", "abc", "c" }; 69 string findName = "c"; 70 71 int findPos = Finder.Find<string>(names, findName); 72 73 Add(23, 32); 74 } 75 76 //鍙傛暟 77 static int Add(int a, int b) 78 { 79 return a + b; 80 } 81 } 82 }
以上是关于娉涘瀷鏂规硶的主要内容,如果未能解决你的问题,请参考以下文章
Android MVP + 娉涘瀷锛屽疄鐜颁簡鍙嬪ソVP浜や簰鍙夾ctivity娼滃湪鐨勫唴瀛樻硠闇茬殑浼樺寲