C#小知识

有VC++基础的人转学C#,先对基础语法作大概了解,然后边做边查, 将查到的东西记录在此处,也提供给有同样需求的朋友.

1.C# 是全面向对象的语言.它没有面向过程的宏.甚至没有全局变量.
  C#通常利用static 静态 或者const 常量来处理一些全局性的内容.但原理上和宏是完全不同的.

2.将ASP.NET的DropDownList清空
   DropDownListAP.Items.Clear();

3.ASP.NET的DropDownList不能产生OnSelectedIndexChanged事件
  将属性中的AutoPostBack设为true试试看.

4.ASP.NET的DropDownList产生OnSelectedIndexChanged事件后会重新初始化各控件,
  为避免重新初始化,在Page_Load中加入条件试试看.
   if (!Page.IsPostBack)
    {
      //初始化代码
    }

5.在ASP.NET中添加一个WebForm
  菜单:  Project -> Add New Item -> Web Form

6.如何在ASP.NET中实现页面间的参数传递
  有好几种方法,这里总结得比较全面,直接上链接,http://blog.163.com/asgo_fanfan/blog/static/873136362011424111124838/


7.如何获取系统当前时间
 string time = System.DateTime.Now.ToString();//日期+时间
 string time = System.DateTime.Now.ToString("yyyy-MM-dd");//只有日期
 string time = System.DateTime.Now.ToString("HH:mm:ss");//只有时间
 注意大小写

8.如何避免Winform中的TreeView执行ExpandAll闪烁
 treeView1.BeginUpdate();
 treeView1.ExpandAll();
 treeView1.EndUpdate();

9.Lazy<T> 实现对象的延迟初始化
在.NET4.0中,可以使用Lazy<T> 来实现对象的延迟初始化,从而优化系统的性能。延迟初始化就是将对象的初始化延迟到第一次使用该对象时

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
   public class Student
   {
      public Student()
      {
         this.Name = "DefaultName";
         this.Age = 0;
         Console.WriteLine("Student is init...");
      }

      public string Name { get; set; }
      public int Age { get; set; }
   }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
   class Program
   {
      static void Main(string[] args)
      {
         Lazy<Student> stu = new Lazy<Student>();
         if(!stu.IsValueCreated)
            Console.WriteLine("Student isn't init!");
         Console.WriteLine(stu.Value.Name);
         stu.Value.Name = "Tom";
         stu.Value.Age = 21;
         Console.WriteLine(stu.Value.Name);
         Console.Read();
      }
   }
}





 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值