当前位置: 首页>>代码示例>>C#>>正文


C# List类代码示例

本文整理汇总了C#中List的典型用法代码示例。如果您正苦于以下问题:C# List类的具体用法?C# List怎么用?C# List使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


List类属于命名空间,在下文中一共展示了List类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertFromString

        private static Thickness ConvertFromString(string s)
        {
            var parts = s.Split(',')
                .Take(4)
                .Select(part => part.Trim());

            if (parts.Count() == 1)
            {
                var uniformLength = double.Parse(parts.First());
                return new Thickness(uniformLength);
            }

            double left = 0, top = 0, right = 0, bottom = 0;

            IList<Action<double>> setValue = new List<Action<double>>
            {
                val => left = val,
                val => top = val,
                val => right = val,
                val => bottom = val,
            };

            var i = 0;
            foreach (var part in parts)
            {
                var v = double.Parse(part);
                setValue[i](v);
                i++;
            }

            return new Thickness(left, top, right, bottom);
        }
开发者ID:Scellow,项目名称:Perspex,代码行数:32,代码来源:ThicknessConverter.cs

示例2: Weapon

        // Constructor(s)
        public Weapon()
            : base()
        {
            this.Damage = Globals.Randomizer.Next(10, 20);
            this.ShieldPiercing = (float)Math.Round(Globals.Randomizer.NextDouble(), 2);
            this.Chance = Globals.Randomizer.Next(20, 30);
            this.Depth = 0.5f;

            this.Texture = TextureManager.weapons[Globals.Randomizer.Next(0, TextureManager.weapons.Count)];

            ShootMethods = new List<Shoot>();
            ShootMethods.Add(FireStandard);
            ShootMethods.Add(FireAiming);
            ShootMethods.Add(FireCrit);
            ShootMethods.Add(FireDelayEnemyShot);
            ShootMethods.Add(FireDamageOverTime);
            ShootMethods.Add(FireChanceToMiss);

            Action = Globals.Randomizer.Next(0, ShootMethods.Count);

            // Initialize weapon
            ShootMethods[Action](Position, Direction, 0, null, true);

            Targets = new List<string>();

            // Description
            LoadDescription();
        }
开发者ID:indietom,项目名称:Outer-Space,代码行数:29,代码来源:Weapon.cs

示例3: Main

        static void Main()
        {
            List<MethodInvoker> list = new List<MethodInvoker>();

            for (int index = 0; index < 5; index++)
            {
                int counter = index * 10;
                list.Add(delegate
                {
                    Console.WriteLine(counter);
                    counter++;
                });
            }

            foreach (MethodInvoker t in list)
            {
                t();
            }

            list[0]();
            list[0]();
            list[0]();

            list[1]();
        }
开发者ID:gourdon,项目名称:C-,代码行数:25,代码来源:MultipleCaptures.cs

示例4: Create

 public void Create(object self, List<Func<object, IFilter>> creators)
 {
     _filters = new IFilter[creators.Count];
     for (var i = 0; i < creators.Count; i++)
     {
         _filters[i] = creators[i](self);
     }
 }
开发者ID:SaladLab,项目名称:Akka.Interfaced,代码行数:8,代码来源:InterfacedActor.PerInstanceFilterList.cs

示例5: Main

 private static void Main(string[] args)
 {
     var contents = new List<Func<int>>();
     for (var i = 4; i < 7; i++)
     {
         int j = i;
         contents.Add(() => j);
     }
     for (var k = 0; k < contents.Count; k++)
         Console.WriteLine(contents[k]());
 }
开发者ID:kodefuguru,项目名称:Presentations,代码行数:11,代码来源:Program.cs

示例6: Main

    static void Main()
    {
        var methods = new List<Action>();
        foreach (var word in new string[] { "hello", "world" })
        {
            methods.Add(() => Console.Write(word + " "));
        }

        methods[0]();
        methods[1]();
    }
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:11,代码来源:IterationVariableOfForeach.cs

示例7: Test_2

	static IEnumerable<int> Test_2 ()
	{
		List<Func<int>> lambdas = new List<Func<int>> ();
		for (int i = 0; i < 4; ++i) {
			int h = i;
			lambdas.Add (() => h);
		}

		for (int i = 0; i < 4; ++i) {
			yield return lambdas[i] ();
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:12,代码来源:gtest-iter-23.cs

示例8: Main

 private static void Main(string[] args)
 {
     var contents = new List<Func<int>>();
     var s = new StringBuilder();
     for (var i = 4; i < 7; i++)
     {
         var j = i;
         contents.Add(() => j);
     }
     for (var k = 0; k < contents.Count; k++)
         s.Append(contents[k]());
     Console.WriteLine(s);
 }
开发者ID:kodefuguru,项目名称:Presentations,代码行数:13,代码来源:Program.cs

示例9: Main

 static void Main()
 {
     var items = new string[] {"Moe", "Larry", "Curly"};
     var actions = new List<Action>{};
     int i;
     for(i=0;i<items.Length;i++) //foreach (string item in items)
     {
         actions.Add(()=>{ Console.WriteLine(items[i]);});
     }
     for (i=0;i<items.Length;i++)
     {
         actions[i]();
     }
 }
开发者ID:elegabriel,项目名称:test_code,代码行数:14,代码来源:CaptureLoop.cs

示例10: LawOfClosures

        static void LawOfClosures()
        {
            var DelayedActions = new List<Func<int>>();
            var s = "";

            for (var i = 4; i < 7; i++)
            {
                DelayedActions.Add(() => i);
            }
            for (var k = 0; k < DelayedActions.Count; k++)
                s += DelayedActions[k]();

            Console.WriteLine(s);
        }
开发者ID:julid29,项目名称:confsamples,代码行数:14,代码来源:Program.cs

示例11: Main

	public static void Main() 
	{
		var actions = new List<Action>();

		var sb = new StringBuilder();
		for (int i = 0; i < 5; i++) {
			int i2 = i;
			actions.Add(() => sb.AppendLine(i2.ToString()));
		}

		for (int i = 0; i < actions.Count; i++)
			actions[i]();

		Console.WriteLine(sb.ToString());
	}
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:15,代码来源:VariableCaptureSemantics.cs

示例12: Split

        public static string[] Split(string str, char[] separators, int maxComponents, StringSplitOptions options)
        {
            ContractUtils.RequiresNotNull(str, "str");
            #if SILVERLIGHT || WP75
            if (separators == null) return SplitOnWhiteSpace(str, maxComponents, options);

            bool keep_empty = (options & StringSplitOptions.RemoveEmptyEntries) != StringSplitOptions.RemoveEmptyEntries;

            List<string> result = new List<string>(maxComponents == Int32.MaxValue ? 1 : maxComponents + 1);

            int i = 0;
            int next;
            while (maxComponents > 1 && i < str.Length && (next = str.IndexOfAny(separators, i)) != -1) {

                if (next > i || keep_empty) {
                    result.Add(str.Substring(i, next - i));
                    maxComponents--;
                }

                i = next + 1;
            }

            if (i < str.Length || keep_empty) {
                result.Add(str.Substring(i));
            }

            return result.ToArray();
            #else
            return str.Split(separators, maxComponents, options);
            #endif
        }
开发者ID:TerabyteX,项目名称:main,代码行数:31,代码来源:StringUtils.cs

示例13: LoadEvents

        private static Dictionary<DateTime, String> LoadEvents(String filePath)
        {
            List<String> activities = new List<String>();
            List<DateTime> timestamps = new List<DateTime>();

            Dictionary<DateTime, String> events = new Dictionary<DateTime, String>();

            int k = 0;
            foreach (String line in File.ReadAllLines(filePath))
            {
                string[] tokens = line.Split(new char[] { ';' });
                Console.WriteLine("Line " + k);
                timestamps.Add(DateTime.Parse(tokens[0]));
                activities.Add(tokens[1]);
                events.Add(DateTime.Parse(tokens[0]), tokens[1]);
                Console.WriteLine("Timestamp per line " + DateTime.Parse(tokens[0]) + " Activity = " + tokens[1]);
                k++;

            }
            var tsArray = timestamps.ToArray();
            var actArray = activities.ToArray();
            Console.WriteLine("tsArray length " + tsArray.Length + ", actArray length " + actArray.Length);
            for (int j = 0; j < tsArray.Length; j++)
            {
                Console.WriteLine("tsArray[" + j + "] = " + tsArray[j].ToString() + " -- actArray[" + j + "] = " + actArray[j].ToString());
            }

            SimulateReadingFile(events);

            return events;
        }
开发者ID:imanhelal,项目名称:RuntimeDeductionCaseID,代码行数:31,代码来源:Program.cs

示例14: Execute

        public bool Execute(List<Vehicle> vehicles)
        {
            try
            {
                foreach (var vehicle in vehicles)
                {
                    var vehicleEntity = _db.Vehicle.Find(vehicle.Id);

                    if (vehicleEntity != null)
                    {
                        vehicleEntity.Id = vehicle.Id;
                        vehicleEntity.BookingId = vehicle.BookingId;
                        vehicleEntity.VehicleType = vehicle.VehicleType;
                        vehicleEntity.TrailerType = vehicle.TrailerType;
                        _db.MarkVehicleAsModified(vehicleEntity);
                        _db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
开发者ID:Mandersen21,项目名称:AmendmentBackend,代码行数:25,代码来源:PostVehicleCommand.cs

示例15: Load

		public virtual IList<ItemToolboxNode> Load (LoaderContext ctx, string filename)
		{
			SystemPackage sp = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetPackageFromPath (filename);
			ReferenceType rt;
			string rname;
			
			if (sp != null) {
				rt = ReferenceType.Package;
				rname = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyFullName (filename, null);
			} else {
				rt = ReferenceType.Assembly;
				rname = filename;
			}
			
			List<ItemToolboxNode> list = new List<ItemToolboxNode> ();
			var types = Runtime.RunInMainThread (delegate {
				// Stetic is not thread safe, it has to be used from the gui thread
				return GuiBuilderService.SteticApp.GetComponentTypes (filename);
			}).Result;
			foreach (ComponentType ct in types) {
				if (ct.Category == "window")
					continue;
				ComponentToolboxNode cn = new ComponentToolboxNode (ct);
				cn.ReferenceType = rt;
				cn.Reference = rname;
				list.Add (cn);
			}
			return list;
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:29,代码来源:ToolboxLoader.cs


注:本文中的List类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。