zoukankan      html  css  js  c++  java
  • C#之静态函数的使用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace while_test
    {
        public class While_test
        {
            //定义while_test类中的Find方法,用于在数组中查找特定的值
            public static int Find(string keyValue,string[] array)
            {
                //定义整型数据i作为数组array的下标
                int i = array.Length - 1;
                while (i >= 0)
                {
                    if (array[i] == keyValue)
                    {
                        break;
                    }
                    i--;
                }
                //返回i值,找到即返回该元素在数组中的小标,否则返回-1
                return i;
            }
        }
        class Program
        {
            static void Main()
            {
                string[] a1 = { "张兰","苗群","洋洋","赵薇","王露","陈浩"};
                Console.WriteLine("输入你要查找的姓名");
                string findValue = Console.ReadLine();
                int arrayIndex = While_test.Find(findValue, a1);
                if (arrayIndex == -1)
                {
                    Console.WriteLine("数组中无此人");
                }
                else
                {
                    Console.WriteLine("此人在数组的第{0}个元素中",arrayIndex+1);
                }
                Console.ReadLine();
            }
        }
    }

  • 相关阅读:
    JDK6的switch支持不是很好
    团队作业(2)
    团队作业(1)
    4月30日
    重构:改善既有代码的设计有感
    4月28日
    4月27日
    4月26日
    4月25日
    4月24日
  • 原文地址:https://www.cnblogs.com/zztong/p/6695245.html
Copyright © 2011-2022 走看看