有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();
}
}
}