c# primer note I
------------------------
★
Foreach :
优点:
1、不用考虑数组起始索引是几
int[] nArray = new int[100];
// Use "foreach" to loop array
foreach( int i in nArray )
2、对于多维数组操作用foreach非常简便
int[,] nVisited = new int[8,8];
// Use "for" to loop two-dimension array
for( int i = 0; i < nVisited.GetLength(0); i++ )
for( int j = 0; j < nVisited.GetLength( 1 ); j++ )
Debug.WriteLine( nVisited[i,j].ToString() );
// Use "foreach" to loop two-dimension array
foreach( int i in nVisited )
Debug.WriteLine( i.ToString() );
3、foreach类型转换
// Init an arraylist object
int[] nArray = new int[100];
ArrayList arrInt = new ArrayList();
arrInt.AddRange( nArray );
// Use "foreach" to loop an arraylist
foreach( int i in arrInt )
Debug.WriteLine( i.ToString() );
// Use "for" to loop an arraylist
for( int i = 0; i < arrInt.Count; i++ )
{
int n = ( int ) arrInt[i];
Debug.WriteLine( n.ToString() );
}
两个限制
在foreach不能修改枚举成员,其次不要对集合进行删除操作。
// Use "foreach" to loop an arraylist
foreach( int i in arrInt )
{
i++;//Can't be compiled
Debug.WriteLine( i.ToString() );
}
// Use "foreach" to loop an arraylist
foreach( int i in arrInt )
{
arrInt.Remove( i );//It will generate error in run-time
Debug.WriteLine( i.ToString() );
}
附--对于记录集的多条数据删除
可以用for来实现,由于在一些记录集中进行删除的时候,在删除操作之后相应的索引也发生了变化,这时候的删除要反过来进行删除
// Use "for" to loop an arraylist
for( int i = arrInt.Count - 1; i >=0; i-- )
{
int n = ( int ) arrInt[i];
if( n == 5 )
arrInt.RemoveAt( i ); // Remove data here
Debug.WriteLine( n.ToString() );
}
http://blog.csdn.net/huang7914/archive/2008/04/16/2296176.aspx
------------------------
★
------------------------
★
------------------------
★
------------------------
★
------------------------
★
------------------------
★
------------------------
★
---------------------
相关文档:
非常简单,在C#中只需要在类的方法的上方敲三下"/"就自动帮你添加相关的代码,你只要按着填写就可以了,而Java则是输入"/**",它也会自动形成相关代码,具体代码如下:
C#
/// <summary>
/// 在此填写总体描述
///</summary>
/// <param name="name">这里填写参数name的描述</param>
public string ......
a. ReportViewer关联Report1.rdlc的简单呈现
b. 对带有报表参数的Report1.rdlc的呈现
c.
利用程式生成的DataSet 填充报表
d. 调用存储过程 生成DataSet 填充报表
==========
简单的呈现
==========
1. 打开VS2005,文件->新建->网站 选择语言种类(C#)
2. 在该解决方案下
设计其已经生成的Default.aspx ......
C#正则表达式编程(二):Regex类用法
对于正则表达式的应用,基本上可以分为验证、提取、分割和替换。仅仅利用Regex类就可以实现验证和简单替换。
利用Regex类实现验证
经历2009年的备案和DNS停止解析风波之后,大部分的带有反馈性的网站和论坛都对一些敏感词进行了过滤,包含有这类敏感词的文章要么内� ......
send :
string path = "E:\\c#\\convey_file\\convey_file\\Form1.cs"; //要传输的文件
TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.0.52"),9999);
FileStream file = new FileStream(path,FileMode.Open,FileAccess.Read); // ......