首页 > 其他分享 >CSharp: Collection

CSharp: Collection

时间:2023-01-27 14:55:07浏览次数:36  
标签:return string System Collection item CSharp using public

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)));
        }
    }

}

  

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; 
        
        }

    }
}

  

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] + " ");
        }

    }

}

  

调用:、

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);

  输出:

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

  

标签:return,string,System,Collection,item,CSharp,using,public
From: https://www.cnblogs.com/geovindu/p/17068906.html

相关文章

  • CSharp: Add,Edit,Del,Select in donet using Entity Framework
     usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Entity;usingSystem.Linq;usingSystem.Runtime.Remoting.Contexts;usingSystem.Text;usi......
  • Java源码解析 Collection<E>
    位置: java.util.Collection<E>interface用途:参数:<E>Iterable<E>子类:接口:方法   int size();  返回这......
  • CSharp: emojione
     ///<summary>///mysql数据库用编码类型utf8mb4///向sqlserver数据库插入emoji表情包///插入emoji的数据时,值value需要......
  • CSharp: SOAP,WSDL
     引用服务有修改,点右键更新 Web.config<?xmlversion="1.0"encoding="utf-8"?><configuration><configSections><sectionname="microsoft.web.services3......
  • CSharp: Lazy Load Pattern in donet core 6
     usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceGeovin.Du.DuLazyLoad.DuGhost......
  • Java反序列化-CommonsCollections2利用链分析
    前言接上篇TemplatesImpl利用链分析,学习了通过TemplatesImpl利用链来进行类加载执行恶意代码,现在来学习一下CommonsCollections2利用链。分析前的准备漏洞组件:commons-c......
  • Apache IoTDB C# SDK Apache-IoTDB-Client-CSharp
    最近今天写了IoTDB的三篇相关文章,完成了安装部署和客户端连接:WindowsServer上部署IoTDB集群DBeaver连接IoTDBDriver将IoTDB注册为Windows服务TsFile是IoTDB的底层数......
  • SwitchableObservableCollection AddRange
    usingSystem;usingSystem.Collections.Generic;usingSystem.Collections.ObjectModel;usingSystem.Collections.Specialized;usingSystem.ComponentModel;using......
  • Java反序列化-CommonsCollections1利用链分析
    前言学习Java基础语法也有1年多的时间了,Java安全基础也学了有半年了,期间通过ctf赛题学习过fastjson的反序列化并了解了其利用链,但并未深入学习并记录笔记。一直都说要赶......
  • Collection集合
    Collection集合常用方法:booleanadd(Ee):添加元素booleanremove(objecto):从集合中移除指定的元素voidclear():清空集合中的元素booleancontains(objecto):判断集合......