本文整理汇总了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);
}
示例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();
}
示例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]();
}
示例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);
}
}
示例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]());
}
示例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]();
}
示例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] ();
}
}
示例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);
}
示例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]();
}
}
示例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);
}
示例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());
}
示例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
}
示例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;
}
示例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;
}
示例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;
}