本文整理汇总了C#中List类的典型用法代码示例。如果您正苦于以下问题:C# List类的具体用法?C# List怎么用?C# List使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
List类属于命名空间,在下文中一共展示了List类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Main2
static void Main2(string[] args)
{
var numReal = new List<double>(80);
Random gerador = new Random();
double maior = 0;
double menor = 0;
double soma = 0;
double media = 0;
for (int i = 0; i < 80; i++)
{
numReal.Add(gerador.NextDouble());
if (i == 0)
{
maior = numReal[i];
menor = numReal[i];
}
soma += numReal[i];
}
media = soma / 80;
for (int i = 0; i < 80; i++)
{
maior = (numReal[i] > maior) ? numReal[i] : maior;
menor = (numReal[i] < menor) ? numReal[i] : menor;
}
Console.WriteLine("Maior: {0:F2}", maior);
Console.WriteLine("Menor: {0:F2}", menor);
Console.WriteLine("Soma: {0:F2}", soma);
Console.WriteLine("Media: {0:F2}", media);
Console.ReadKey();
}
开发者ID:GreicyMatias,项目名称:GreicyRepositorio,代码行数:31,代码来源:Unidade_Complementar.cs
示例17: GetPendingChanges
public static List<ProjectItem> GetPendingChanges()
{
var projectItems = new List<ProjectItem>();
var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
var projectCollections = new List<RegisteredProjectCollection>(RegisteredTfsConnections.GetProjectCollections());
foreach (var registeredProjectCollection in projectCollections)
{
var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(registeredProjectCollection);
var versionControl = projectCollection.GetService<VersionControlServer>();
var workspace = versionControl.GetWorkspace(dte.Solution.FileName);
foreach (var pendingChange in workspace.GetPendingChangesEnumerable())
{
if (pendingChange.FileName != null && (pendingChange.FileName.EndsWith(".cs") || pendingChange.FileName.EndsWith(".config")))
{
var projectItem = dte.Solution.FindProjectItem(pendingChange.FileName);
if (projectItem != null)
{
projectItems.Add(projectItem);
}
}
}
}
return projectItems;
}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:25,代码来源:TfsService.cs
示例18: Nesting
/// <summary>
/// get nesting of circles within given dimensions
/// </summary>
/// <param name="circles">input planar surfaces to be cut</param>
/// <param name="spacing">spacing between input result</param>
/// <param name="width">width of sheet</param>
/// <param name="length">length of sheet</param>
internal Nesting(List<PolyCurve> polycurves, double spacing, double width, double length)
{
Width = width;
Length = length;
Spacing = spacing;
ListPolyCurve = TileVertical(MapToXYPlane(polycurves), spacing);
}
开发者ID:Hanxuelong,项目名称:BecauseWeDynamo,代码行数:14,代码来源:Nesting.cs
示例19: Main
static void Main(string[] args)
{
List<ulong> testIntegers = new List<ulong>() { 117, 0, 1, 4, 69, 642, 932, 6903, 69382, 504967, 4028492, 902409102, 1403102045, ulong.MaxValue };
ConsoleTests(testIntegers);
UnicodeTests(testIntegers);
}
开发者ID:ryan-nauman,项目名称:Shrtn,代码行数:7,代码来源:Program.cs
示例20: Initialize
protected void Initialize()
{
Instance.PropertyChanged += Instance_PropertyChanged;
PropertyInfo[] propertyInfos = Instance.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
// Inspect each INotifyPropertyChanged
if (propertyInfo.PropertyType.GetInterfaces().Contains(typeof(INotifyPropertyChanged)))
{
INotifyPropertyChanged propertyValue = propertyInfo.GetValue(Instance) as INotifyPropertyChanged;
if (propertyValue != null)
{
propertyValues.Add(propertyInfo.Name, propertyValue);
propertyValue.PropertyChanged += PropertyValue_PropertyChanged;
}
}
// Inspect each DependsOn attribute
DependsOnAttribute dependsOnAttribute = propertyInfo.GetCustomAttribute<DependsOnAttribute>();
if (dependsOnAttribute != null)
{
foreach (string property in dependsOnAttribute.Properties)
{
List<PropertyInfo> dependencies;
if (!propertyDependencies.TryGetValue(property, out dependencies))
propertyDependencies.Add(property, dependencies = new List<PropertyInfo>());
if (!dependencies.Contains(propertyInfo))
dependencies.Add(propertyInfo);
}
}
}
}
开发者ID:jbatonnet,项目名称:taskmanager,代码行数:35,代码来源:DependencyManager.cs
注:本文中的List类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论