随笔分类 -  .net

摘要:<asp:FileUpload runat="server" ID="imgUpload" AllowMultiple="true" /> 后台: HttpFileCollection files = Request.Files; if (files.Count > 0 && imgUpload.H 阅读全文
posted @ 2016-03-08 14:22 lishidefengchen
摘要:private HttpRequest Request; private HttpResponse Response; public void ProcessRequest(HttpContext context) { //不让浏览器缓存 context.Response.Buffer = true 阅读全文
posted @ 2016-02-26 17:46 lishidefengchen
摘要:escape()或者encode()编码一下要用的字符串。 阅读全文
posted @ 2016-01-28 17:55 lishidefengchen
摘要:比如list有2个值,当你运行完上述代码后,你会发现,你的ls中的Num没有按你预期的那样从0开始,导致这个问题的原因是:在你查询完毕后,执行的Count()方法,会导致查询语句中Num=num++再次执行一遍。为了避免这个问题,建议最好不要在查询语句中使用运算语句(比如自加,自减等); 阅读全文
posted @ 2015-11-13 15:21 lishidefengchen
摘要:public class SomeType{}//等价于public class SomeType{ public SomeType():base(){}}【解释】如果定义的类没有显示定义任何构造器,C#编译器将定义一个默认(无参)构造器。在它的实现中,只是简单地调用了基类的无参构造器。 阅读全文
posted @ 2015-08-04 15:46 lishidefengchen
摘要:partial、struct、interface是C#编译器特有的,CLR对此一无所知。 阅读全文
posted @ 2015-05-28 09:37 lishidefengchen
摘要:【应用场景】程序集A访问程序集B定义的Internal访问类型的类的成员。【使用方式】在构建程序集B的时候,引入System.Runtime.CompilerServices,以此来添加InternalsVisibleToattribute【例子】程序集B——using System;using S... 阅读全文
posted @ 2015-05-27 13:10 lishidefengchen
摘要:【实例代码】using System;public sealed class SomeType //-------------1{ //嵌套类 private class SomeNestedType{} ... 阅读全文
posted @ 2015-05-25 19:01 lishidefengchen
摘要:利用系统安装盘来安装.net3.5时,遇到的问题。【命令】dism.exe /online /enable-feature /featurename:NetFX3 /Source:F:\sources\sxs【原因】DOS窗口以管理员运行即可。 阅读全文
posted @ 2015-05-19 09:48 lishidefengchen
摘要:【Class中,可能包含的成员】常量,字段,实例构造器,类型构造器,方法,操作符重载,转换操作符,属性,事件,类型(Class) 阅读全文
posted @ 2015-05-19 09:25 lishidefengchen
摘要:1、代码使用 dynamic 表达式/变量来调用一个成员时,编译器会生成特殊的 IL 代码来描述所需的操作。这种特殊的代码称为 payload(有效载荷)。在运行时,payload 代码根据当前由 dynamic 表达式/变量引用的对象的实际类型来决定具体执行的操作。【例子】private stat... 阅读全文
posted @ 2015-05-15 16:36 lishidefengchen
摘要:C#是一种类型安全语言:所有的表达式都解析成某个类型的一个实例,在编译器生成的代码中,只会执行对这个类型来说有效的操作。【优势】许多错误能在编译时就检测到,确保代码在执行这段代码前是正确的;生成更小、更快的代码,因为代码在编译时能进行更多假设,并在生成的IL和元数据中落实那些假设; 阅读全文
posted @ 2015-05-14 09:26 lishidefengchen
摘要:【重写Equals注意的事项】1. Equals 必须是自反的;--x.Equals(x)肯定为 true2. Equals 必须是对称的;--x.Equals(y)肯定返回与y.Equals(x)相同的值3. Equals 必须是可传递的;--x.Equals(y)返回true, y.Equals... 阅读全文
posted @ 2015-05-08 18:39 lishidefengchen
摘要:【示例代码】 1 using System; 2 //Point is a Value Type 3 internal struct Point { 4 private Int32 m_x, m_y; 5 6 public Point(Int32 x,Int32 y){ 7 ... 阅读全文
posted @ 2015-05-08 17:20 lishidefengchen
摘要:【注意】:如果知道自己写的代码会造成编译器反复对一个值类型进行装箱,请改成用手动方式对值类型进行装箱。【好处】:代码会变得更小、更快。【例子】:using System;public sealed class Program { public static void Main() { /... 阅读全文
posted @ 2015-05-08 09:47 lishidefengchen
摘要:【推荐】System.Collections.Generic.List【原因】泛型集合类List在操作值类型的集合时可以不进行 装箱/拆箱 处理。使得性能较ArrayList提高了相当大的程度。因为托管堆中需要创建的对象次数减少了,所以需要应用程序执行的垃圾回收次数也相应减少。除此之外,开发人员还获... 阅读全文
posted @ 2015-05-06 16:18 lishidefengchen
摘要:【值类型在装箱过程中内部发生的事情】1.在托管堆中分配好内存。分配的内存量是值类型的各个字段需要的内存量加上托管堆的所有对象都有的两个额外成员(类型对象指针和同步快索引)需要的内存量。2.值类型的字段复制到新分配的堆内存。3.返回对象的地址。现在,这个地址是对一个对象的引用,值类型现在是一个引用类型... 阅读全文
posted @ 2015-05-06 15:43 lishidefengchen
摘要:【引用类型和值类型的区别】//引用类型(由于使用了‘class’)class SomeRef { public Int32 x; }//值类型(由于使用了‘struct’)struct SomeVal { public Int32 x; }static void ValueTypeDemo() {... 阅读全文
posted @ 2015-05-05 17:55 lishidefengchen
摘要:1. CLR 支持两种类型:引用类型 和 值类型。2. FCL 中大多数的类型是 引用类型,但程序中使用最多的是 值类型。【引用类型】内存必须从托管堆上分配。堆上分配的每个对象都有一个额外的成员,这些成员必须初始化。对象上的其他字节(为字段而设)总是设为零。从托管堆上分配一个对象时,可能强制执行一次... 阅读全文
posted @ 2015-05-05 15:20 lishidefengchen
摘要:【注意】勾选这个选项会对应用程序的整体性能造成一些影响,但是会更加安全。具体情况根据项目需求来决定。 阅读全文
posted @ 2015-05-05 10:15 lishidefengchen