黑马程序员_C#学习之数组(代码)

这篇博客主要探讨了C#编程中的数组使用,包括在Windows Phone 7开发和.NET框架下的应用。作者强调了与.NET培训和社区交流的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

---------------------- Windows Phone 7手机开发.Net培训、期待与您交流! ----------------------

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

namespace Ex7_6
{
    class Program
    {
        static void Main(string[] args)
        {

           //C#二位数组转置输出
            int[,] OriginalArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, 
                                { 10, 11, 12 }, { 13, 14, 15 } };
            int[,] ReversionArray=new int[3,5];
            for (int i = 0; i <= OriginalArray.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= OriginalArray.GetUpperBound(1); j++)
                {
                    ReversionArray[j, i] = OriginalArray[i, j];
                }
            }
            Console.WriteLine("原始的数组为:");
            PrintArray(OriginalArray);
            Console.WriteLine("转置后的数组为:");
            PrintArray(ReversionArray); 

     Console.ReadLine();
        }
        public static void PrintArray(int[,] intArray)
        {
            for (int i = 0; i <= intArray.GetUpperBound(0); i++)
            {
                for (int j = 0; j <=intArray.GetUpperBound(1); j++)
                {
                    Console.Write(intArray[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
    }
}





 

    

 

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

namespace text_
{
    class Program
    {
        public static int a;
        public static void OneString(string s)
        {

            //C#输入一串字符串求单词个数
            string[] thisString = s.Split(new char[] { ' ' });
            a = thisString.Length;
           //测试有无多个连续空格代码
           // for (int i=0; i < thisString.Length; i++)
           // {
           //     Console.WriteLine("qq*"+thisString[i]+"*qq");
           // }
            for (int i = 0; i < thisString.Length; i++)
              {
                 if (thisString[i] == "")
                     a--;

              }

            Console.WriteLine("此字符串中{0}个单词!", a);
        }

        static void Main(string[] args)
        { 
            //string onestring = "   a b  c  d e  f g h  ";
            Console.WriteLine("输入一个包含单词的字符串:");
            string onestring = Console.ReadLine();
            Console.WriteLine(onestring);
            
            OneString(onestring);
            Console.Read();
        }
    }
}


 

	   int[] a = new int[12];
            Random ran = new Random();
            for (int i = 0; i < a.Length; i++)
            {
            one:           
                a[i] =(int)ran.Next()+1;
                for(int j=0;j<i;j++)
                {
                    if(a[i]==a[j])
                        goto one;
                }

            }
            foreach (int n in a)
                Console.Write(n + " ");

           int temp;
           int m = 0;
            for (int j = 0; j<a.Length; j++)
            {
                temp = j;
                for(int i=j+1;i<a.Length;i++ )
                {
                    if (a[i] < a[temp])
                        temp = i;
                }
                if(temp!=j)
                    m = a[j];
                    a[j] = a[temp];
                    a[temp] = m;
            }

            Console.WriteLine();
            Console.WriteLine("输出排序后的结果:");
            foreach (int n in a)
                Console.Write(n + " ");

 

 

---------------------- Windows Phone 7手机开发.Net培训、期待与您交流! ----------------------

详细请查看:http://net.itheima.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值