笔记

1, Dictionary转换List

Dictionary<int, int> dic = new Dictionary<int, int>();
// 1
List<int> list = new List<int>(dic.Keys);
// 2
list.AddRange(dic.Values);

 2, 时间转换

DateTime time = DateTime.MinValue;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
time = startTime.AddMilliseconds(serverTime);
GameDebug.LogError(time);

 3, List.Find()

   List<int> nums = new List<int>() { 1, 3, 5, 6 };
   int num = nums.Find((wantNum) => { return wantNum == 3; });

   List<Person> persons = new List<Person>(){
    new Person("a",11),
    new Person("b",22),
    new Person("c",33)
   };
   Person p = persons.Find((wantP) =>
   {
     if (wantP.Age == 22)
         return true;
     return false;
   });

 4,Remove跟RemoveAt

            ArrayList arr = new ArrayList() { "a", "b", "c" };
            int index = arr.IndexOf("b");
            arr.RemoveAt(index);

            ArrayList arr = new ArrayList() { "a", "b", "c" };
            arr.Remove("b");
            
            // 这两种删除性能上并无差别====>源码
            public virtual void Remove(object obj)
            {
                int index = this.IndexOf(obj);
                if (index >= 0)
                {
                    this.RemoveAt(index);
                }
            }

            public virtual void RemoveAt(int index)
            {
                if ((index < 0) || (index >= this._size))
                {
                    throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
                }
                this._size--;
                if (index < this._size)
                {
                    Array.Copy(this._items, index + 1, this._items, index, this._size - index);
                }
                this._items[this._size] = null;
                this._version++;
            }

 5,时间转换

        DateTime dt = new DateTime(leftScon);
        lb_leftTime.text = string.Format("{0:00}", "{1:00}", "{2:00}", dt.Hour, dt.Minute, dt.Second);
TimeSpan ts
= new TimeSpan(0, 0, leftScon); lb_leftTime.text = ts.ToString();

 

posted @ 2016-05-13 15:50  贴心小冰棍  阅读(138)  评论(0编辑  收藏  举报