C#其他
1.switch - if ...else if...
switch(表达式)
{
case 值:
。。。。。
break;
case 值:
。。。。。
break;
default:
。。。。。
break;
}
2.while -- for
int i = 0;//变量初化。
while(循环条件)
{
//循环体
//i++;//状态改变。
}
do...while();
foreach(元素类型 变量 in 集合或数组)
{
}
3.锯齿数组——数组的数组
定义:
a.定义数组的数组:
int[][] a = new int[3][];
b.定义一维数组:
int[] b1 = new int[4]{1,2,3,4};
int[] b2 = new int[3]{5,6,7};
int[] b3 = new int[5]{9,10,11,12,13};
c.把一维数组加到数组的数组中去
a[0] = b1;
a[1] = b2;
a[2] = b3;
使用:
a[行][列] = 。。。
a[行][列]
a.Length == ??? 3
a[0].Length = ????? 4
4.集合:
(1)链表——每个存储的值都会分配一个索引号,通过索引号可对每个元素赋值或取值。
弱类型:
using System.Collection;
ArrayList list = new ArrayList();
强类型:
using System.Collection.Generic;
List<类型> list = new List<类型>();
list.Clear();
list.Add(value);
list.Insert(索引号,value);
list.RemoveAt(索引号);
list.Count;
(2)哈希表——每个元素都由两部分组成,一部分叫key,一部分叫value
弱类型:
using System.Collection;
Hashtable table = new Hashtable();
强类型:
using System.Collection.Generic;
Dictionary<类型,类型> dic = new Dictionary<类型,类型>();
dic.Clear();
dic.Add(key,value);
dic.Remove(key)
dic.Count;
5.递归——自己调自己 —— 将来可能会用到,但是现在仅做了解。
int Add(int a)
{
int b = Add(a+1);
Console.WriteLine(b);
}
void 讲故事()
{
Console.Write("从前。。。,老和尚说:");
讲故事();
}
void 找子级文件夹(当前文件夹)
{
if(当前文件夹下没有子文件夹)
{
return;
}
找子级文件夹(当前文件夹下的第一个子文件夹);
}
//猴子吃桃子。
static int TaoZi(int day) //接收天数,返回这一天的桃子数
{
if (day == 7)
{
return 1;
}
int c = (TaoZi(day+1) + 1) * 2;
return c;
}
//程序员与富翁:
static double Money(int day)
{
if (day == 1)
{
return 0.01;
}
double a = Money(day-1) * 2;
return a;
}
6.枚举:——结构体。枚举也是我们自己定义的类型。
随机推荐
- sql 索引创建
--格式 --CREATE [索引类型] INDEX 索引名称--ON 表名(列名)--WITH FILLFACTOR = 填充因子值0~100--GO ----------------------- ...
- java.io.DataInput接口和java.io.DataOutput接口详解
public interface DataInput DataInput 接口用于从二进制流中读取字节,并重构所有 Java 基本类型数据.同时还提供根据 UTF-8 修改版格式的数据重构 Strin ...
- HGE游戏引擎之实战篇,渐变的游戏开场
#include <hge.h> #include "menuitem.h" //#include <hgefont.h> #include <hge ...
- ActiveMQ实现负载均衡+高可用部署方案(转)
本文转自:http://www.open-open.com/lib/view/open1400126457817.html%20 一.架构和技术介绍 1.简介 ActiveMQ 是Apache出品,最 ...
- listview 滑动以后设置最上面一行为整行展示
需求: listview显示的第一行永远为整行,不能为半行. 参考: android listview 每次滑动整行 1. 添加 listview 的 setOnScrollListener() 事件 ...
- SQL Server 复制 订阅与发布
SQL Server 复制 订阅与发布 通过SQL Server 2008数据库复制实现数据库同步备份 SqlServer2008 数据库同步的两种方式(Sql JOB) SqlServer2008 ...
- rsync增量传输大文件优化技巧
问题 rsync用来同步数据非常的好用,特别是增量同步.但是有一种情况如果不增加特定的参数就不是很好用了.比如你要同步多个几十个G的文件,然后网络突然断开了一下,这时候你重新启动增量同步.但是发现等了 ...
- iOS 判断相机权限是否被限制,判断相机是否可以使用
判断相机权限是否被限制 需要导入 AVFoundation 类 [objc] view plain copy #import <AVFoundation/AVFoundation.h> ...
- CodeIgniter配置之config
配置说明 $config['language']:指定项目语言包.需要注意的时Codeigniter自带的类库错误提示语言包位于/system/language/english/目录下,当这里配置非e ...
- dirname和basename命令
dirname返回文件所在目录路径,而basename则相反,去掉路径返回最后的文件名. dirname指令 1.功能:从给定的包含绝对路径的文件名中去除文件名(非目录的部分),然后返回剩下的路径(目 ...