看了一些基础视频,才发现自己的基础比较薄弱,有很多基础知识都不知道。这里总汇一些基础知识。

1:

foreach不仅可以作用于list类的索引集合,还可以遍历dictionary类,这一点比for更简便。

            Dictionary<int, long> dary = new Dictionary<int, long>();
dary.Add(, );
dary.Add(, );
dary.Add(, );
string sall = string.Empty; //在vs2010中,打出foreach后,双击tab键,自动跳出后面的语句,非常快速方便。
//这个技巧同样适用于for
foreach (var item in dary)
{
sall += item.ToString() + " ";
}
Console.WriteLine(sall);
Console.ReadLine();
return;

2:使用filestream读取写入文件的操作

        public static void CopyFile(string soucre, string target,int length)
{
//1、我们创建一个负责读取的流 使用using关键字可以在读取后立即释放相应的资源 不用额外再写close() dispose()方法
using (FileStream fsRead = new FileStream(soucre, FileMode.Open, FileAccess.Read))
{
//2、创建一个负责写入的流
using (FileStream fsWrite = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
byte[] buffer = new byte[length];
//因为文件可能会比较大,所以我们在读取的时候 应该通过一个循环去读取
while (true)
{
//返回本次读取实际读取到的字节数 读取后fsread的流自动提升到读取到的最后一位
int r = fsRead.Read(buffer, , buffer.Length);
//如果返回一个0,也就意味什么都没有读取到,读取完了
if (r == )
{
break;
}
//Console.WriteLine(fsRead.Position);
//Console.WriteLine(fsWrite.Position);
fsWrite.Write(buffer, , r);
}
}
}
}

Visual Studio 2010 实用功能总结  这两篇文章总结了大量VS2010的开发小技巧

原文链接1    原文链接2

最新文章

  1. javascript的canvas绘图的基本用法
  2. RESTful API URI 设计: 判断资源是否存在?
  3. Bois设置教程
  4. CF# Educational Codeforces Round 3 B. The Best Gift
  5. The &quot;get&quot; method should be used when the form is idempotent---正交的两个概念---
  6. 1057 N的阶乘
  7. 254. Factor Combinations
  8. Working——流程关系状态表
  9. 赵雅智_BroadcastReceiver电话监听
  10. JavaEE Tutorials (7) - 在会话bean中使用异步方法调用
  11. 原生Js 两种方法实现页面关键字高亮显示
  12. SDAU课程练习--problemA(1000)
  13. Hadoop编译方法
  14. 【BZOJ4034】【HAOI2015】树上操作
  15. SSM商城开发学习
  16. noi2016旷野大作战
  17. Linux系统命令 3
  18. 双网卡设置(转:https://www.cnblogs.com/visionfeng/p/5825078.html)
  19. UI BOL 练习 get value set attr
  20. contos7忘记root密码怎么办

热门文章

  1. Linux上设置RAID 10
  2. Deepin-安装node
  3. 基于Spring-SpringMVC-Mybatis的简单样例
  4. NYOJ 158 省赛来了
  5. .net面试整理
  6. Hibernate 之 Persistence
  7. BindException 无法指定被请求的地址
  8. Jquery与Dom对象相互转化
  9. npm i macaca-android -g 无法安装成功、安装成功后运行脚本提示app-debug.apk不存在的问题
  10. INT_PTR数据类型