嗚嗚喔學習筆記: 6月 2015

搜尋此網誌

2015年6月23日 星期二

ASP.net MVC5 - [ LINQ ]


LINQ - 常用四種方法 where , any , all , select


程式碼:
var number = new int[] { 10, 200, 300, 400, 500 };

//查詢 number[i] > 300 的數值
var where = number.Where(p => p > 300);
foreach( var item in where)
{
    System.Diagnostics.Debug.WriteLine("where item = " + item);
}

//是否有 number[i] == 200 的數值
var any = number.Any(p => p == 200);
System.Diagnostics.Debug.WriteLine("any number[i] == 200 : " + any);

//是否全部都是 number[i] == 300
var all = number.All(p => p == 300);
System.Diagnostics.Debug.WriteLine("all number[i] == 300 : " + all);

//提取資料 並且和成新資料
var select = number.Select(p => "tim"+p).ToArray();
foreach (var item in select)
{
    System.Diagnostics.Debug.WriteLine("select item = " + item);
}

輸出結果 : 

where item = 400
where item = 500
any number[i] == 200 : True
all number[i] == 300 : False
select item = tim10
select item = tim200
select item = tim300
select item = tim400

select item = tim500

2015年6月16日 星期二

Android[ ArrayList ]




程式碼:

        int a =1;
        int b =2;
        int c =3;
        ArrayList<Integer> list = new ArrayList();
        list.add(a);
        list.add(b);
        list.add(c);

        for(int i = 0 ; i < list.size(); i++ )
            Log.d("ooxx","first LinkedList"+list.get(i));

        for(int i = 0 ; i < list.size(); i++ )
        {
            if (list.get(i) == 2 ) {
                list.remove(i);
                list.add(2);
            }
        }

        for(int i = 0 ; i < list.size(); i++ )

            Log.d("ooxx","second LinkedList"+list.get(i));

結果: