C#中的数组操作练习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace 数组
{
    class Program
    {
        static void Main(string[] args)
        {
            //从一个整数数组中取出最大的整数
            //int[] nums ={ 1,8,5,10,9};
            //int max=0;
            //for (int i = 0; i < nums.Length;i++ ) {


            //    if(max<nums[i]){




            //        max = nums[i];


            //    }




            //}
            //Console.WriteLine(max);


            //计算一个整数数组所有元素的和
            //int[] nums = { 1, 8, 5, 10, 9 };
            //int sum=0;
            //for (int i = 0; i < nums.Length;i++ ) {


            //    sum += nums[i];


            //}
            //Console.WriteLine(sum);
            //将一个字符串数组输出为|分割的形式比如a|b|c
            //string[] str = { "张三","李四","王五"};


            //for (int i = 0; i < str.Length;i++ )
            //{
            //     Console.Write(str[i]);
            //    if(i==str.Length-1){




            //        Console.Write("");


            //        break;
            //    }


            //    Console.Write("|");


            //}


            //将数组中的正数的值+1 负数的话元素的值-1
            //int[] nums = { 1, 8, 5, 10, 9, -1 };
            //for (int i = 0; i < nums.Length; i++)
            //{
            //    if (nums[i] >= 0)
            //    {
            //        nums[i] = nums[i] + 1;


            //    }
            //    else { nums[i] = nums[i] - 1; }


            //}
            //int j = 0;
            //while (j<nums.Length)
            //{
            //    Console.WriteLine(nums[j]);


            //    j ++;
            //}
            //将一个整数数组的元素的值 放到字符串数组中;
            //int[] nums = { 1, 2, 3, 4, 5, 6 };
            //string[] stringNums = new string[nums.Length];


            //for (int i = 0; i < nums.Length; i++)
            //{


            //    stringNums[i] = nums[i].ToString();
            //    Console.WriteLine(stringNums[i]);
            //}


            //将一个字符串数组里元素的值反序;
            string[] strs = { "张三", "李四", "王五", "你妹" ,"亲爱的"};
            string temp;
            for (int i = 0;
                i < strs.Length - i;
                i++)
            {


                temp = strs[i];
                strs[i] = strs[strs.Length - i - 1];
                strs[strs.Length - i - 1] = temp;






            }


            for (int i = 0; i < strs.Length; i++)
            {
                Console.WriteLine(strs[i]);


            }
            //链接两个int数组为新的Int数组
            //int[] nums1 = { 1, 2, 3 };
            //int[] nums2 = { 4, 5, 6 };
            //int[] newNums = new int[nums1.Length + nums2.Length];
            //for (int i = 0; i < nums1.Length; i++)
            //{
            //    newNums[i] = nums1[i];
              
            //}
            //int j = 0;
            //for (int i = nums2.Length; i < newNums.Length; i++)
            //{
                 
            //    newNums[i] = nums2[j];
            //    j++;


            //}
            //for (int i = 0; i < newNums.Length; i++)
            //{


            //    Console.WriteLine(newNums[i]);


            //}
            Console.ReadKey();


        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值