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. |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
数值算法
标签:
data structures
, 数据结构
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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