List and ArrayList
生活随笔
收集整理的這篇文章主要介紹了
List and ArrayList
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
List<> and ArrayList Class Diagrams
Using the Bit Complement of the BinarySearch() Result
代碼
?1using?System;
?2using?System.Collections.Generic;
?3class?Program
?4{
?5????static?void?Main()
?6????{
?7????????List<string>?list?=?new?List<string>();
?8????????int?search;
?9
10????????list.Add("public");
11????????list.Add("protected");
12????????list.Add("private");
13
14????????list.Sort();
15
16????????search?=?list.BinarySearch("protected?internal");
17????????if?(search?<?0)
18????????{
19????????????/**//*The?bitwise?complement?(~)?of?this?value?is?
20?????????????*?the?index?of?the?next?element?larger?than?the?
21?????????????*?element?being?sought,?or?the?total?element?count?
22?????????????*?if?there?is?no?greater?value.?This?provides?a?
23?????????????*?convenient?means?to?insert?new?values?into?the?
24?????????????*?list?at?the?specific?location?so?as?to?maintain?sorting?*/
25????????????list.Insert(~search,?"protected?internal");
26????????}
27
28????????foreach?(string?accessModifier?in?list)
29????????{
30????????????Console.WriteLine(accessModifier);
31????????}
32????????Console.ReadKey();
33????}
34}?
Demonstrating FindAll() and Its Predicate Parameter
代碼
?1using?System;
?2using?System.Collections.Generic;
?3using?Microsoft.VisualStudio.TestTools.UnitTesting;
?4
?5class?Program
?6{
?7
?8????static?void?Main()
?9????{
10????????List<int>?list?=?new?List<int>();
11????????list.Add(1);
12????????list.Add(2);
13????????list.Add(3);
14????????list.Add(2);
15
16????????List<int>?results?=?list.FindAll(Even);
17????????/**//*
18?????????*?命名空間:Microsoft.VisualStudio.TestTools.UnitTesting
19?????????*?程序集:Microsoft.VisualStudio.QualityTools.UnitTestFramework(在?microsoft.visualstudio.qualitytools.unittestframework.dll?中)
20?????????*/
21????????Assert.AreEqual(2,?results.Count);
22????????Assert.IsTrue(results.Contains(2));
23????????Assert.IsFalse(results.Contains(3));
24????}
25????public?static?bool?Even(int?value)
26????{
27????????if?((value?%?2)?==?0)
28????????{
29????????????return?true;
30????????}
31????????else
32????????{
33????????????return?false;
34????????}
35????}
36}
Using the Bit Complement of the BinarySearch() Result
代碼
?1using?System;
?2using?System.Collections.Generic;
?3class?Program
?4{
?5????static?void?Main()
?6????{
?7????????List<string>?list?=?new?List<string>();
?8????????int?search;
?9
10????????list.Add("public");
11????????list.Add("protected");
12????????list.Add("private");
13
14????????list.Sort();
15
16????????search?=?list.BinarySearch("protected?internal");
17????????if?(search?<?0)
18????????{
19????????????/**//*The?bitwise?complement?(~)?of?this?value?is?
20?????????????*?the?index?of?the?next?element?larger?than?the?
21?????????????*?element?being?sought,?or?the?total?element?count?
22?????????????*?if?there?is?no?greater?value.?This?provides?a?
23?????????????*?convenient?means?to?insert?new?values?into?the?
24?????????????*?list?at?the?specific?location?so?as?to?maintain?sorting?*/
25????????????list.Insert(~search,?"protected?internal");
26????????}
27
28????????foreach?(string?accessModifier?in?list)
29????????{
30????????????Console.WriteLine(accessModifier);
31????????}
32????????Console.ReadKey();
33????}
34}?
Demonstrating FindAll() and Its Predicate Parameter
代碼
?1using?System;
?2using?System.Collections.Generic;
?3using?Microsoft.VisualStudio.TestTools.UnitTesting;
?4
?5class?Program
?6{
?7
?8????static?void?Main()
?9????{
10????????List<int>?list?=?new?List<int>();
11????????list.Add(1);
12????????list.Add(2);
13????????list.Add(3);
14????????list.Add(2);
15
16????????List<int>?results?=?list.FindAll(Even);
17????????/**//*
18?????????*?命名空間:Microsoft.VisualStudio.TestTools.UnitTesting
19?????????*?程序集:Microsoft.VisualStudio.QualityTools.UnitTestFramework(在?microsoft.visualstudio.qualitytools.unittestframework.dll?中)
20?????????*/
21????????Assert.AreEqual(2,?results.Count);
22????????Assert.IsTrue(results.Contains(2));
23????????Assert.IsFalse(results.Contains(3));
24????}
25????public?static?bool?Even(int?value)
26????{
27????????if?((value?%?2)?==?0)
28????????{
29????????????return?true;
30????????}
31????????else
32????????{
33????????????return?false;
34????????}
35????}
36}
轉載于:https://www.cnblogs.com/nanshouyong326/archive/2007/05/10/741889.html
總結
以上是生活随笔為你收集整理的List and ArrayList的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个女生qq霸气网名!
- 下一篇: 爱不释手(Typingfaster)1.