C#2

同名的两个类如果在不同的命名空间中,相互之间是不会混淆的。

一个名为TextHello的命名空间中创建一个名为Program的类,引用方法 TextHello.Program

我们常用的Console类存在于System命名空间中,这意味着它的全名为System.Console,但每次输入总显得麻烦,这时你可以用 using System ;  命令来限定要使用的命名空间。在写代码的时候只需要输入 Console即可,免去了总是输入System的麻烦。

C#求数组长度        数组名.Length

  1. namespace sorter  
  2. {  
  3.     public class SelectionSorter   //类名
  4.     {  
  5.         private int min;  
  6.         public void Sort(int[] arr)  
  7.         {  
  8.             for (int i = 0; i < arr.Length - 1; ++i)  
  9.             {  
  10.                 min = i;  
  11.                 for (int j = i + 1; j < arr.Length; ++j)  
  12.                 {  
  13.                     if (arr[j] < arr[min])  
  14.                     {  
  15.                         min = j;  
  16.                     }  
  17.                 }  
  18.                 int t = arr[min];  
  19.                 arr[min] = arr[i];  
  20.                 arr[i] = t;  
  21.             }  
  22.         }  
  23.     }  
  24.   
  25.     class Program  
  26.     {  
  27.         static void Main(string[] args)  
  28.         {  
  29.             int[] arrInt = new int[] { 4, 2, 7, 1, 8, 3, 9, 0, 5, 6 };  
  30.             SelectionSorter selSor = new SelectionSorter();   //调用类时 需要清空原先的类
  31.             selSor.Sort(arrInt);  
  32.             foreach (int i in arrInt)    //提取数组中的整数
  33.             {  
  34.                 Console.WriteLine(i);  
  35.             }  
  36.             Console.ReadKey();  
  37.         }  
  38.     }  
  39. }  

int[] Sum = new int[50];
Random rd = new Random();///
// 先用for循环给数组取随机数.
for (int s = 0; s <= Sum.Length - 1; s++) // Sum.Length是数组的一个属性,Length代表数组的长度
{
Sum[s] = rd.Next(100);
}

原文地址:https://www.cnblogs.com/wshyj/p/6038442.html