CSharp: Collection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CSharpDataStructuresAlgorithms
{
 
    /// <summary>
    /// 直接存取群集 Collection
    /// geovindu,Geovin Du
    /// </summary>
    public struct Name
    {
 
        /// <summary>
        ///
        /// </summary>
        private string fname, mname, lname;
        /// <summary>
        ///
        /// </summary>
        /// <param name="first"></param>
        /// <param name="middle"></param>
        /// <param name="last"></param>
        public Name(string first, string middle, string last)
        {
            fname = first;
            mname = middle;
            lname = last;
        }
        /// <summary>
        ///
        /// </summary>
        public string firstName
        {
            get
            {
                return fname;
            }
            set
            {
                fname = firstName;
            }
        }
        /// <summary>
        ///
        /// </summary>
        public string middleName
        {
            get
            {
                return mname;
            }
            set
            {
                mname = middleName;
            }
        }
        /// <summary>
        ///
        /// </summary>
        public string lastName
        {
            get
            {
                return lname;
            }
            set
            {
                lname = lastName;
            }
        }
        /// <summary>
        /// 全名
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return (String.Format("{0} {1} {2}", fname, mname, lname));
        }
        /// <summary>
        /// 缩写名
        /// </summary>
        /// <returns></returns>
        public string Initials()
        {
            return (String.Format("{0}{1}{2}", fname.Substring(0, 1), mname.Substring(0, 1), lname.Substring(0, 1)));
        }
    }
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
 
namespace CSharpDataStructuresAlgorithms
{
 
    /// <summary>
    /// Collection 群集
    /// </summary>
    public class DuCollection: CollectionBase
    {
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        public void Add(object item)
        {
 
            InnerList.Add(item);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        public void Romove(object item)
        {
            InnerList.Remove(item);
        }
        /// <summary>
        ///
        /// </summary>
        public new void Clear()
        {
            InnerList.Clear();
        }
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Contains(object item)
        {
            return InnerList.Contains(item);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public int IndexOf(object item)
        {
            return InnerList.IndexOf(item);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public new int Count()
        {
            return InnerList.Count;
         
        }
 
    }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CSharpDataStructuresAlgorithms
{
 
    /// <summary>
    ///
    /// </summary>
    public class Timing
    {
        TimeSpan startingTime;
        TimeSpan duration;
        /// <summary>
        ///
        /// </summary>
        public Timing()
        {
            startingTime = new TimeSpan(0);
            duration = new TimeSpan(0);
        }
        /// <summary>
        ///
        /// </summary>
        public void StopTime()
        {
            duration =
            Process.GetCurrentProcess().Threads[0].
            UserProcessorTime.Subtract(startingTime);
 
        }
        /// <summary>
        ///
        /// </summary>
        public void StartTime()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            startingTime =
            Process.GetCurrentProcess().Threads[0].
            UserProcessorTime;
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public TimeSpan Result()
        {
            return duration;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arr"></param>
        public static void BuildArray(int[] arr)
        {
            for (int i = 0; i < 100000; i++)
                arr[i] = i;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arr"></param>
        public static void DisplayNums(int[] arr)
        {
            for (int i = 0; i <= arr.GetUpperBound(0); i++)
                Console.Write(arr[i] + " ");
        }
 
    }
 
}

  

调用:、

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Console.WriteLine("Hello, Geovin Du!");
Name myName = new Name("Michael", "Mason", "McMillan");
string fullName, inits;
fullName = myName.ToString();
inits = myName.Initials();
Console.WriteLine("My name is {0}.", fullName);
Console.WriteLine("My initials are {0}.", inits);
int[] nums = new int[100000];
Timing.BuildArray(nums);
Timing tObj = new Timing();
tObj.StartTime();
Timing.DisplayNums(nums);
tObj.StopTime();
Console.WriteLine("time (.NET): " + tObj.Result().TotalSeconds);

  输出:

1
2
3
Hello, Geovin Du!
My name is Michael Mason McMillan.
My initials are MMM.

  

posted @   ®Geovin Du Dream Park™  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2022-01-27 CSharp: iTextSharp 5.13.2 create pdf
2018-01-27 JqGrid: Add,Edit,Del in asp.net
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示