栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C# > C#教程

C#数组反转与排序实例分析

C#教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#数组反转与排序实例分析

本文实例分析了C#数组反转与排序的方法。分享给大家供大家参考。具体实现方法如下:

C#数组反转
复制代码 代码如下:using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
 
namespace 数据反转 

    class Program 
    { 
        static void Main(string[] args) 
        { 
            string[] strAllay = { "毛泽东", "李世民", "秦始皇", "成吉思汗", "习近平","邓小平"}; 
            string s; 
            for (int i = 0; i < strAllay.Length / 2; i++)//strAllay.Length/2是因为经过(将数组的长度值除以2)次就可以将数组成员进行反转了 
            { 
                s = strAllay[i]; 
                strAllay[i] = strAllay[strAllay.Length - 1 - i];//如果i等于数组第一项值(毛泽东)的时候,将它与最后一个值(邓小平)互换。 
                strAllay[strAllay.Length - 1 - i] = s; 
            } 
            foreach (string ss in strAllay) 
            { 
                Console.Write(ss+" " ); 
            } 
            Console.ReadKey(); 
        } 
    } 
}
C#数组排序:
复制代码 代码如下:using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
 
namespace 数组 

    class Program 
    { 
        static void Main(string[] args) 
        { 
            //输出一个数组里的最大的数值; 
             
            //按大小顺序输出数组的值 
            int[] list = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 ,100,25,38}; 
             
                ///

 
         /// 插入排序法 
         ///
 
         ///  
         
             for (int i = 1; i < list.Length; i++) 
              { 
                 int t = list[i]; 
                 int j = i; 
                 while ((j > 0) && (list[j - 1] > t)) 
                 { 
                     list[j] = list[j - 1]; 
                     --j; 
                 } 
                 list[j] = t; 
             } 
 
                foreach (int forStr in list) 
                { 
                    Console.Write(forStr + " "); 
                } 
            Console.ReadKey(); 
        } 
    } 
}

希望本文所述对大家的C#程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/125734.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号