我來讀代碼之三(d-podium)

1:泛型

 System.Collections.Generic

http://msdn.microsoft.com/zh-cn/library/system.collections.generic(VS.80).aspx

// type parameter T in angle brackets public class GenericList<T> {     // The nested class is also generic on T     private class Node     {         // T used in non-generic constructor         public Node(T t)         {             next = null;             data = t;         }         private Node next;         public Node Next         {             get { return next; }             set { next = value; }         }                 // T as private member data type         private T data;         // T as return type of property         public T Data          {             get { return data; }             set { data = value; }         }     }     private Node head;         // constructor     public GenericList()     {         head = null;     }     // T as method parameter type:     public void AddHead(T t)     {         Node n = new Node(t);         n.Next = head;         head = n;     }     public IEnumerator<T> GetEnumerator()     {         Node current = head;         while (current != null)         {             yield return current.Data;             current = current.Next;         }     } } ——————————————————————

class TestGenericList {     static void Main()     {         // int is the type argument         GenericList<int> list = new GenericList<int>();         for (int x = 0; x < 10; x++)         {             list.AddHead(x);         }         foreach (int i in list)         {             System.Console.Write(i + " ");         }         System.Console.WriteLine("/nDone");     } }

下面涉及到了反射!!!

public virtual object getValue(T t, string valueName)     {         object ret=default(object);         System.Reflection.PropertyInfo property = t.GetType().GetProperty(valueName);         if (property == null)             return null;         ret=t.GetType().InvokeMember(valueName,System.Reflection.BindingFlags.GetProperty,null,t,new object[]{});         return ret;     }

    public virtual void setValue(T t, string valueName,string val)     {         System.Reflection.PropertyInfo property = t.GetType().GetProperty(valueName);         if (property == null)             return;         val = "001";         t.GetType().InvokeMember(valueName, System.Reflection.BindingFlags.SetProperty, null, t, new object[] { val });     }

    public virtual object getValue(T t, string valueName)     {         object ret = default(object);         System.Reflection.MemberInfo[] member = t.GetType().GetMember(valueName);         if (member == null)             return null;         ret = t.GetType().InvokeMember(valueName, System.Reflection.BindingFlags.GetField, null, t, new object[] { });         return ret;     }

    public virtual void setValue(T t, string valueName, string val)     {         System.Reflection.MemberInfo[] member = t.GetType().GetMember(valueName);         if (member == null)             return;         t.GetType().InvokeMember(valueName, System.Reflection.BindingFlags.SetField, null, t, new object[] { val });     }

2:?與??

*變量定義中含有一個問號,意思是這個數據類型是NullAble類型的。 *變量定義中含有兩個問號,意思是取所賦值??左邊的,如果左邊爲null,取所賦值??右邊的。

cred.adaptorName = WebConfigurationManager.AppSettings["LDAPAdaptor"] ?? "Domestic";

3:public ItemMapping(Control target, String boundproperty, String targetproperty)             : this(target, boundproperty, targetproperty, null, null)這裏的:表示繼承,只能用於構造函數。         {         }

        public ItemMapping(Control target, String boundproperty):this(target, boundproperty,null,null,null)         {這裏的:表示繼承,只能用於構造函數。         }         public ItemMapping(Control target, String boundproperty, String targetproperty, String format, ICustomFormatter formatter)         {             if (target == null) throw new ArgumentNullException("target");             if (boundproperty == null) throw new ArgumentNullException("boundproperty");

            this.mTarget = target;             this.mBound = boundproperty;             this.mTgtProp = targetproperty;             this.mFormat = format;             this.mFormatter = formatter;         }

4:string.Format("Service Url:{0}", “aaabbbccc”)

相當於:"Service Url:aaabbbccc"

5:

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">             <triggers>                 <asp:AsyncPostBackTrigger ControlID="RadioButtonList1" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>                 <asp:AsyncPostBackTrigger ControlID="Search1" EventName="Click"></asp:AsyncPostBackTrigger>                 <asp:AsyncPostBackTrigger ControlID="Search" EventName="Click"></asp:AsyncPostBackTrigger>             </triggers>         </asp:UpdatePanel>

微軟自帶的ajax控件:Ajax Extensions。把你所需要異步update的區域用updatepanel包起來,然後設置哪些trigger可以影響這個panel。另外還需要ScriptManager這個控件。

注意;先創建一個Ajax Website(裝AJAX時會裝上ScriptManager的)

6:if (lst == null) throw new ArgumentNullException("lst"); throw,哈哈!

發佈了19 篇原創文章 · 獲贊 5 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章