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

一个名为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. class Program
  25. {
  26. static void Main(string[] args)
  27. {
  28. int[] arrInt = new int[] { 4, 2, 7, 1, 8, 3, 9, 0, 5, 6 };
  29. SelectionSorter selSor = new SelectionSorter();   //调用类时 需要清空原先的类
  30. selSor.Sort(arrInt);
  31. foreach (int i in arrInt)    //提取数组中的整数
  32. {
  33. Console.WriteLine(i);
  34. }
  35. Console.ReadKey();
  36. }
  37. }
  38. }

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);
}

随机推荐

  1. Sublime Text3快捷方式与使用技巧

    Sublime Text 3 快捷键精华版 Ctrl+Shift+P:  打开命令面板Ctrl+P:  搜索项目中的文件Ctrl+G: 跳转到第几行Ctrl+W: 关闭当前打开文件Ctrl+Shift ...

  2. spring beans源码解读之 ioc容器之始祖--DefaultListableBeanFactory

    spring Ioc容器的实现,从根源上是beanfactory,但真正可以作为一个可以独立使用的ioc容器还是DefaultListableBeanFactory,因此可以这么说, DefaultL ...

  3. GOOGLE的专业使用方法(转)

    搜索引擎命令大全! 1.双引号 把搜索词放在双引号中,代表完全匹配搜索,也就是说搜索结果返回的页面包含双引号中出现的所有的词,连顺序也必须完全匹配.bd和Google 都支持这个指令.例如搜索: “s ...

  4. C++ 遇到的问题小结

    1. cannot convert 'std::basic_string<char>' to 'int' in assignment ... 原始code如下: int id2; std: ...

  5. Measuring the amount of writes in InnoDB redo logs

    Choosing a good InnoDB log file size is key to InnoDB write performance. This can be done by measuri ...

  6. Navicat导入数据时发生了报错 --- 1153 - Got a packet bigger than 'max_allowed的处理办法

    今天我在使用Navicat导入.sql文件数据时,发现本来是80万条的数据,结果只导入了10万条左右,而且在其错误信息日志中,我发现了这样一条错误:1153 - Got a packet bigger ...

  7. RESTful架构

    RESTful架构 1.什么是RESTful API设计原则 REST是Representational State Transfer的简写,意为“表现层状态转换” 是一种对资源状态进行操作的设计规则 ...

  8. sql server 常用的系统存储过程

      系统存储过程 说明 sp_databases 列出服务上的所有数据库 sp_helpdb 报告有关指定数据库或所有数据库的信息 sp_renamedb 更改数据库的名称 sp_tables 返回当 ...

  9. 重新加载maven项目的依赖项

    最近在调试reportNG,测试允许完以后,报告总是使用的testNG的格式,并且只有index和overview两个文件. 找了好多帖子,大家都是那么设置的都没有问题,难道是哥人品不好?错! 大家基 ...

  10. mysql 远程访问

    如何开启MySQL的远程帐号-1)首先以 root 帐户登陆 MySQL 在 Windows 主机中点击开始菜单,运行,输入“cmd”,进入控制台,然后cd 进入MySQL 的 bin 目录下,然后输 ...