本文整理汇总了C#中IList.Count方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Count方法的具体用法?C# IList.Count怎么用?C# IList.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rewrite
// Arg(ControllerName),Param(..),.. -> Arg(ControllerName),Arg('Index'),...
public static IList<Token> Rewrite(IList<Token> tokens)
{
//"--command"
if (tokens.Count() >= 2
&& tokens[0].TokenType==TokenType.Argument
&& tokens[0].Value.EqualsIC("help")
&& tokens[1].TokenType==TokenType.Argument)
{
tokens[1] = new Token(tokens[1].Value,TokenType.ParameterValue,tokens[1].Index);
tokens.Insert(1,new Token("command",TokenType.Parameter,1));
//index:2
if (tokens.Count() >= 4) { tokens[3] = new Token(tokens[3].Value, TokenType.ParameterValue, tokens[1].Index); }
tokens.Insert(3, new Token("action", TokenType.Parameter, 2));
}
//help maps to index (should have routing here)
if (tokens.Count() == 0)
{
tokens.Add(new Token("help",TokenType.Argument,0));
}
//Index rewrite:
var indexToken= new Token("Index", TokenType.Argument,1);
if (tokens.Count()>=2
&& tokens[1].TokenType!=TokenType.Argument
&& tokens[0].TokenType==TokenType.Argument)
{
tokens.Insert(1,indexToken);
}
else if (tokens.Count()==1
&& tokens[0].TokenType==TokenType.Argument)
{
tokens.Add(indexToken);
}
return tokens;
}
示例2: Render
/// <summary>
/// Convert numbers to spark chart strings.
/// </summary>
/// <param name="data">List or Array of numbers</param>
/// <returns>empty string if <paramref name="data"/>is <code>null</code> or empty.</returns>
public static String Render(IList<double> data)
{
var ticks = TickProvider.Ticks;
if (data == null || data.Count == 0)
return string.Empty;
char[] res = new char[data.Count()];
double min = data.Min();
double max = data.Max();
double step = (max - min) / (ticks.Length - 1);
if (step.Equals(0d)) step = 1;
for (var i = 0; i < data.Count(); i++)
{
var val = data[i];
double d = (val - min)/step;
// if it's 10^-10 close to its rounded, round; floor otherwise
int tick = (int) ((Math.Abs(Math.Round(d) - d) < 1e-10) ? Math.Round(d) : Math.Floor((val - min) / step));
res[i] = ticks[tick];
}
return new string(res);
}
示例3: BuildMatrix
private int[,] BuildMatrix(IList<Drop> goblet, int blocksCount, int chunkSize)
{
var rowsCount = goblet.Count() * chunkSize;
var columnsCount = (blocksCount * chunkSize) + 1;
var matrix = new int[rowsCount, columnsCount];
for (int dropIdx = 0; dropIdx < goblet.Count(); dropIdx++)
{
var drop = goblet[dropIdx];
for (int i = 0; i < chunkSize; i++)
{
var row = (dropIdx * chunkSize) + i;
matrix[row, columnsCount - 1] = drop.Data[i];
foreach (var part in drop.SelectedParts)
{
var col = (part * chunkSize) + i;
matrix[row, col] = 1;
}
}
}
return matrix;
}
示例4: TableInfo
/// <summary>
/// Initialises a new instance of the <see cref="TableInfo"/> class.
/// </summary>
/// <param name="columns">The columns that are mapped for the table.</param>
/// <param name="identifierStrategy">The identifier strategy used by the table.</param>
/// <param name="name">The name of the table.</param>
/// <param name="schema">The database schema the table exists within (e.g. 'dbo'); otherwise null.</param>
/// <exception cref="ArgumentNullException">Thrown if columns or name are null.</exception>
/// <exception cref="MappingException">Thrown if no there is a problem with the column mappings.</exception>
public TableInfo(
IList<ColumnInfo> columns,
IdentifierStrategy identifierStrategy,
string name,
string schema)
{
if (columns == null)
{
throw new ArgumentNullException("columns");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
this.columns = new ReadOnlyCollection<ColumnInfo>(columns);
this.identifierStrategy = identifierStrategy;
this.name = name;
this.schema = schema;
this.identifierColumn = columns.FirstOrDefault(c => c.IsIdentifier);
this.insertColumnCount = columns.Count(c => c.AllowInsert);
this.updateColumnCount = columns.Count(c => c.AllowUpdate);
this.ValidateColumns();
}
示例5: SolveFive
private int SolveFive(BombSettings settings, IList<Color> colors)
{
if (settings.SerialLastDigit == Parity.NotSet)
{
throw new NeedSerialLastDigitException();
}
// If the last wire is black and the last digit of the serial number is odd, cut the fourth wire.
else if (colors.Last() == Color.Black && settings.SerialLastDigit == Parity.Odd)
{
return 4;
}
// Otherwise, if there is exactly one red wire and there is more than one yellow wire, cut the first wire.
else if (colors.Count(c => c == Color.Red) == 1 && colors.Count(c => c == Color.Yellow) > 1)
{
return 1;
}
// Otherwise, if there are no black wires, cut the second wire.
else if (colors.Count(c => c == Color.Black) == 0)
{
return 2;
}
// Otherwise, cut the first wire.
else
{
return 1;
}
}
示例6: crossProduct2
/// <summary>
/// The cross product of two double vectors, A and B, which are of length, 2.
/// In actuality, there is no cross-product for 2D. This is shorthand for 2D systems
/// that are really simplifications of 3D. The returned scalar is actually the value in
/// the third (read: z) direction.
/// </summary>
/// <param name = "A">1D double Array, A</param>
/// <param name = "B">1D double Array, B</param>
/// <returns></returns>
public static double crossProduct2(IList<double> A, IList<double> B)
{
if (((A.Count() == 2) && (B.Count() == 2))
|| ((A.Count() == 3) && (B.Count() == 3) && A[2] == 0.0 && B[2] == 0.0))
return A[0] * B[1] - B[0] * A[1];
throw new Exception("This cross product \"shortcut\" is only used with 2D vectors to get the single value in the,"
+ "would be, Z-direction.");
}
示例7: HandleCommand
public override void HandleCommand(IList<string> paramList, IrcUser user, bool isIngameCommand)
{
int num;
if (paramList.Count() == 1)
{
// display random quote
Connection.GetData(Data.UrlQuote, "get", jObject =>
{
if ((bool)jObject["success"])
{
Utils.SendChannel((string)jObject["result"].SelectToken("id") + ": " +
(string)jObject["result"].SelectToken("quote"));
}
else
{
Utils.SendChannel("No quotes found.");
}
}, Utils.HandleException);
}
else if (paramList[1] == "add")
{
if (isIngameCommand == false)
{
var quote = "";
for (var l = 2; l < paramList.Count(); l++)
{
quote = quote + paramList[l] + " ";
}
Connection.GetData(string.Format(Data.UrlQuoteAdd, user.Nick, user.Hostmask, quote.Trim()),
"get", jObject => Utils.SendChannel(string.Format("Quote #{0} has been added.", jObject["result"].SelectToken("id"))), Utils.HandleException);
}
else
{
Utils.SendChannel("This command is restricted to the IRC channel only.");
}
}
else if (int.TryParse(paramList[1], out num))
{
Connection.GetData(string.Format(Data.UrlQuoteSpecific, num), "get", jObject =>
{
if ((bool)jObject["success"])
{
Utils.SendChannel((string)jObject["result"].SelectToken("quote"));
}
else
{
Utils.SendChannel("Specific quote not found.");
}
}, Utils.HandleException);
}
else
{
Utils.SendChannel("Usage: !quote add <message>");
}
}
示例8: PrintReportFooter
public virtual void PrintReportFooter(StreamWriter streamWriter, IList<AllItem> allItems)
{
int drCount = allItems.Count(ai => ai.Classification == "Dr");
int crCount = allItems.Count(ai => ai.Classification == "Cr");
decimal drAmount = allItems.Where(ai => ai.Classification == "Dr").Sum(ai => ai.Amount);
decimal crAmount = allItems.Where(ai => ai.Classification == "Cr").Sum(ai => ai.Amount);
streamWriter.WriteLine(string.Format(this.reportFooterFormat, drCount, drAmount, crCount, crAmount));
}
示例9: Create
public static DailyBuildSummary Create(DateTime date, IList<BuildDetails> dailyBuilds)
{
return new DailyBuildSummary()
{
Date = date,
FailedBuilds = dailyBuilds.Count(b => b.Status == BuildState.Broken),
TotalBuilds = dailyBuilds.Count(),
NumberChangedFiles = dailyBuilds.Sum(b => b.NumberChangedFiles)
};
}
示例10: GenerateCurveSegments
public IList<CurveSegment> GenerateCurveSegments(IList<DataPoint> dataPoints)
{
var numDataPoints = dataPoints.Count();
if (numDataPoints < 3) throw new ArgumentException("Not enough data points");
var lastKnownSlope = 0.0;
var lastKnownSlopeMagnitude = 0.0;
var listOfCurveSegments = new List<CurveSegment>();
var listOfCurrentPoints = new List<DataPoint>();
listOfCurrentPoints.Add(dataPoints.First());
for (var i = 1; i < dataPoints.Count(); i++)
{
var lastDataPoint = dataPoints[i - 1];
var currentDataPoint = dataPoints[i];
var discoveredSlope = currentDataPoint.YCoordinate - currentDataPoint.YCoordinate;
var discoveredSlopeMagnitude = Math.Abs(discoveredSlope);
/*
* Test discovered slope value. There's only three possibilities:
* 1. The discovered slope is "zero", which means it's still a part of the current segment
* 2. The discovered slope is positive
* 3. The discovered slope is negative
*
* Compare with the previous slope, which can be:
* 1. Positive
* 2. Negative
* 3. "Zero"
*/
/*
* If the last known slope is zero or if the previous slope was negative and the current slope is positive
* or if the previous slope was positive and the current slope is negative, seal the current segment and
* create a new one
*/
if ((lastKnownSlopeMagnitude < Limits.MaxPrecision && discoveredSlopeMagnitude > Limits.MaxPrecision) ||
(lastKnownSlope < 0 && discoveredSlope > 0) ||
(lastKnownSlope > 0 && discoveredSlope < 0))
{
listOfCurveSegments.Add(new CurveSegment(listOfCurrentPoints));
listOfCurrentPoints = new List<DataPoint>();
}
//The slopes are the same polarity
listOfCurrentPoints.Add(currentDataPoint);
lastKnownSlope = discoveredSlope;
lastKnownSlopeMagnitude = discoveredSlopeMagnitude;
}
return listOfCurveSegments;
}
示例11: GetResult
private static int GetResult(IList<Tree> list)
{
var total = 0;
for (var i = 0; i < list.Count(); i++)
{
total += list[i].Age;
}
return total/list.Count();
}
示例12: Length
public static double Length(IList<IGeoLocation> cities)
{
var length = 0d;
for (var i = 0; i < cities.Count() - 1; i++)
{
length = length + Distance(cities[i], cities[i + 1]);
}
length = length + Distance(cities[cities.Count() - 1], cities[0]);
return length;
}
示例13: should_parse_objects_symbols_and_properties_when_parsing_more_complex_xml_content
public void should_parse_objects_symbols_and_properties_when_parsing_more_complex_xml_content()
{
Lexemes = Parser.Parse(ComplexXml);
Lexemes.Count.ShouldBe(136);
Lexemes.Count(lx => lx.Type == LexemType.Comment).ShouldBe(6);
}
示例14: GetFibLikeSequence
private static IList<ulong> GetFibLikeSequence(IList<ulong> seedSequence, int length)
{
IList<ulong> sequence = new List<ulong>();
int count = seedSequence.Count();
if (length <= count)
{
sequence = seedSequence.Take((int)length).ToList();
}
else
{
sequence = seedSequence;
for (int i = count; i < length; i++)
{
ulong num = 0;
for (int j = 0; j < count; j++)
{
num += sequence[sequence.Count - 1 - j];
}
sequence.Add(num);
}
}
return sequence;
}
示例15: FindPositionPart
public static string FindPositionPart(IList<string> parts, int cursorPosition, out int foundPartsIndex, out int cursorInPartPosition)
{
cursorInPartPosition = 0;
var partsComplete = parts.Aggregate(String.Empty, (aggr, s) => aggr + s);
for (int i = 0; i < parts.Count(); i++) {
var partsLower = parts.Take(i).Aggregate(String.Empty, (aggr, s) => aggr + s);
var partsUpper = parts.Take(i + 1).Aggregate(String.Empty, (aggr, s) => aggr + s);
var b = partsLower.Length;
var t = partsUpper.Length;
if ((cursorPosition >= b && cursorPosition < t) || partsUpper == partsComplete) {
if (parts[i] == WorkDayParser.itemSeparator.ToString() || parts[i] == WorkDayParser.hourProjectInfoSeparator.ToString()) {
// cursor left of separator
foundPartsIndex = i - 1;
var prevPart = parts.ElementAt(foundPartsIndex);
// find out where in the found part the cursor is, need to use prevpart an its length
cursorInPartPosition = prevPart.Length;
return prevPart;
} else {
// find out where in the found part the cursor is
cursorInPartPosition = cursorPosition - b;
foundPartsIndex = i;
return parts.ElementAt(i);
}
}
}
// not found
foundPartsIndex = -1;
return String.Empty;
}