本文整理汇总了C#中IEnumerable.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.ElementAt方法的具体用法?C# IEnumerable.ElementAt怎么用?C# IEnumerable.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.ElementAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildTeachersTable
/// <summary>
/// BuildTeachersTable
/// </summary>
/// <param name="ws"></param>
/// <param name="Teachers"></param>
private static void BuildTeachersTable(ExcelWorksheet ws, IEnumerable<OfficeVisitsByTeacher> Teachers)
{
ws.Column(1).Width = 17.86;
ws.Column(2).Width = 12.43;
//Set Header titles
ws.Cells[4, 1].Value = "Teachers";
ws.Cells[4, 1].Style.Font.Bold = true;
ws.Cells[5, 1].Value = "Teacher Name";
ws.Cells[5, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin);
// ws.Cells[5, 1].AutoFilter = true;
ws.Cells[5, 2].Value = "Office Visits";
ws.Cells[5, 2].Style.Border.BorderAround(ExcelBorderStyle.Thin);
// ws.Cells[5, 2].AutoFilter = true;
//Get Data for Teachers
for (int i = 0; i < Teachers.Count(); i++)
{
ws.Cells[i + 6, 1].Value = Teachers.ElementAt(i).sent_by_contact_name;
ws.Cells[i + 6, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin);
ws.Cells[i + 6, 2].Value = Teachers.ElementAt(i).total_visits;
ws.Cells[i + 6, 2].Style.Border.BorderAround(ExcelBorderStyle.Thin);
}
//Set Header style
using (ExcelRange rng = ws.Cells[4, 1, 5 + Teachers.Count(), 2])
{
rng.Style.Border.BorderAround(ExcelBorderStyle.Medium);
}
}
示例2: GetUnion
public static VectorRectangle GetUnion(IEnumerable<VectorRectangle> list)
{
if (list == null || list.Count() == 0)
{
throw new ArgumentException("list can't be null and must contain at least one element.");
}
VectorRectangle result = new VectorRectangle();
result.Position = list.ElementAt(0).Position;
result.Size = list.ElementAt(0).Size;
VectorRectangle lowest = list.ElementAt(0);
VectorRectangle rightest = list.ElementAt(0);
foreach (VectorRectangle rect in list) {
if (rect.Left < result.Left)
result.Position = new Vector2(rect.Left, result.Position.Y);
if (rect.Right > rightest.Right)
rightest = rect;
if (rect.Top < result.Top)
result.Position = new Vector2(result.Position.X, rect.Top);
if (rect.Bottom > lowest.Bottom)
lowest = rect;
}
result.Size = new Vector2(result.Size.X, lowest.Bottom - result.Top);
result.Size = new Vector2(rightest.Right - result.Left, result.Size.Y);
return result;
}
示例3: Forecast
public ForecastEntry Forecast(IEnumerable<DataEntry> dataEntries, int period, dynamic strategyParameters)
{
if (period - 1 < 0)
return null;
int numberOfPeriods = strategyParameters.PeriodCount;
if (numberOfPeriods > dataEntries.Count())
throw new ArgumentException("The number of periods can not be greater than the number of entries.");
double value;
if (dataEntries.Count() == 1 || period == 1)
value = dataEntries.ElementAt(0).Value;
else if (period < numberOfPeriods)
value = dataEntries.ElementAt(period - 1).Value;
else if (dataEntries.Count() > 1 && period <= dataEntries.Count() + 1)
value =
dataEntries.Take(period - 1).Reverse().Take(numberOfPeriods).Reverse().Sum(entry => (entry.Value))/
numberOfPeriods;
else
value = dataEntries.Reverse().Take(numberOfPeriods).Reverse().Sum(entry => (entry.Value))/
numberOfPeriods;
return new ForecastEntry
{
Period = period,
DataEntry = period > dataEntries.Count() ? dataEntries.Last() : dataEntries.ElementAt(period - 1),
ForecastValue = value,
ConfidenceIntervalLow = value,
ConfidenceIntervalHigh = value,
IsHoldout = period > dataEntries.Count()*0.7 //holdout data is always 70 percent
};
}
示例4: FindYieldN
public static double FindYieldN(double y, IEnumerable<Object> otherParams)
{
double P = (double) otherParams.ElementAt(0);
double C = (double) otherParams.ElementAt(1);
long N = (long) otherParams.ElementAt(2);
return AnnuityWithCandyandN(C, y, N) - P;
}
示例5: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 2);
var args = arguments.ElementAt(0).Value as ExcelDataProvider.IRangeInfo;
var criteria = arguments.ElementAt(1).ValueFirst != null ? ArgToString(arguments, 1) : null;
var retVal = 0d;
if (args == null)
{
var val = arguments.ElementAt(0).Value;
if (criteria != null && Evaluate(val, criteria))
{
var lookupRange = arguments.ElementAt(2).Value as ExcelDataProvider.IRangeInfo;
retVal = arguments.Count() > 2
? lookupRange.First().ValueDouble
: ConvertUtil.GetValueDouble(val, true);
}
else
{
throw new ExcelErrorValueException(eErrorType.Div0);
}
}
else if (arguments.Count() > 2)
{
var lookupRange = arguments.ElementAt(2).Value as ExcelDataProvider.IRangeInfo;
retVal = CalculateWithLookupRange(args, criteria, lookupRange, context);
}
else
{
retVal = CalculateSingleRange(args, criteria, context);
}
return CreateResult(retVal, DataType.Decimal);
}
示例6: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 2);
var args = arguments.ElementAt(0).Value as ExcelDataProvider.IRangeInfo; //IEnumerable<FunctionArgument>;
var criteria = arguments.ElementAt(1).Value;
ThrowExcelErrorValueExceptionIf(() => criteria == null || criteria.ToString().Length > 255, eErrorType.Value);
var retVal = 0d;
if (arguments.Count() > 2)
{
var sumRange = arguments.ElementAt(2).Value as ExcelDataProvider.IRangeInfo;//IEnumerable<FunctionArgument>;
retVal = CalculateWithSumRange(args, criteria.ToString(), sumRange, context);
}
else
{
if (args != null)
{
retVal = CalculateSingleRange(args, criteria.ToString(), context);
}
else
{
retVal = CalculateSingleRange((arguments.ElementAt(0).Value as IEnumerable<FunctionArgument>),
criteria.ToString(), context);
}
}
return CreateResult(retVal, DataType.Decimal);
}
示例7: Forecast
public ForecastEntry Forecast(IEnumerable<DataEntry> dataEntries, int period, dynamic strategyParameters)
{
if (period - 1 < 0)
return null;
double alpha = strategyParameters.Alpha;
double beta = strategyParameters.Beta;
double value;
if (dataEntries.Count() < 3 || period < 3)
value = dataEntries.ElementAt(0).Value;
else if (dataEntries.Count() > 1 && period <= dataEntries.Count() + 1)
value = GenerateForecast(3, period, alpha, beta, dataEntries, dataEntries.First().Value, 0);
else
value = GenerateForecast(3, dataEntries.Count() + 1, alpha, beta, dataEntries, dataEntries.First().Value,
0);
return new ForecastEntry
{
Period = period,
DataEntry = period > dataEntries.Count() ? dataEntries.Last() : dataEntries.ElementAt(period - 1),
ForecastValue = value,
ConfidenceIntervalLow = value,
ConfidenceIntervalHigh = value,
IsHoldout = period > dataEntries.Count()*0.7 //holdout data is always 70 percent
};
}
示例8: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 2);
var firstArg = arguments.ElementAt(0);
var args = firstArg.Value as IEnumerable<FunctionArgument>;
if (args == null && firstArg.IsExcelRange)
{
args = new List<FunctionArgument>(){ firstArg };
}
var criteria = arguments.ElementAt(1).Value;
ThrowExcelErrorValueExceptionIf(() => criteria == null || criteria.ToString().Length > 255, eErrorType.Value);
var retVal = 0d;
if (arguments.Count() > 2)
{
var secondArg = arguments.ElementAt(2);
var lookupRange = secondArg.Value as IEnumerable<FunctionArgument>;
if (lookupRange == null && secondArg.IsExcelRange)
{
lookupRange = new List<FunctionArgument>() {secondArg};
}
retVal = CalculateWithLookupRange(args, criteria.ToString(), lookupRange, context);
}
else
{
retVal = CalculateSingleRange(args, criteria.ToString(), context);
}
return CreateResult(retVal, DataType.Decimal);
}
示例9: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 2);
var row = ArgToInt(arguments, 0);
var col = ArgToInt(arguments, 1);
ThrowExcelErrorValueExceptionIf(() => row < 0 && col < 0, eErrorType.Value);
var referenceType = ExcelReferenceType.AbsoluteRowAndColumn;
var worksheetSpec = string.Empty;
if (arguments.Count() > 2)
{
var arg3 = ArgToInt(arguments, 2);
ThrowExcelErrorValueExceptionIf(() => arg3 < 1 || arg3 > 4, eErrorType.Value);
referenceType = (ExcelReferenceType)ArgToInt(arguments, 2);
}
if (arguments.Count() > 3)
{
var fourthArg = arguments.ElementAt(3).Value;
if (fourthArg is bool && !(bool)fourthArg)
{
throw new InvalidOperationException("Excelformulaparser does not support the R1C1 format!");
}
}
if (arguments.Count() > 4)
{
var fifthArg = arguments.ElementAt(4).Value;
if (fifthArg is string && !string.IsNullOrEmpty(fifthArg.ToString()))
{
worksheetSpec = fifthArg + "!";
}
}
var translator = new IndexToAddressTranslator(context.ExcelDataProvider, referenceType);
return CreateResult(worksheetSpec + translator.ToAddress(col, row), DataType.ExcelAddress);
}
示例10: Execute
public static Result Execute(IEnumerable<string> args)
{
var input = args.ElementAt(1);
var output = args.ElementAt(2);
return Migrate(input, output);
}
示例11: Convert
public static IEnumerable<Price> Convert(IEnumerable<Price> shareData, IEnumerable<SplitEvent> splits)
{
int cumaltiveUpdateIndex = 0;
decimal cumaltiveAdj = splits.First().cumalitveAdjustment;
foreach (var d in shareData.Skip(1))
{
if (splits.ElementAt(cumaltiveUpdateIndex).date <= d.date)
{
cumaltiveUpdateIndex++;
cumaltiveAdj = splits.ElementAt(cumaltiveUpdateIndex).cumalitveAdjustment;
}
yield return new Price()
{
date = d.date,
openPrice = d.openPrice * cumaltiveAdj,
highPrice = d.highPrice * cumaltiveAdj,
lowPrice = d.lowPrice * cumaltiveAdj,
closePrice = d.closePrice * cumaltiveAdj,
//volume = long.Parse(fields[5]),
//adjClose = decimal.Parse(fields[6])
};
}
}
示例12: DoesStatementRequireOutputPort
/// <summary>
/// Checks wheter an outport is required for a Statement with the given
/// index. An outport is not required if there are no defined variables
/// or if any of the defined variables have been declared again later on
/// in the same code block.
/// </summary>
/// <param name="statementVariables">A list of lists, each of which
/// contains variables defined by a Statement at the index. This list
/// can be obtained from calling GetStatementVariables method.</param>
/// <param name="index">The index of the Statement for which this call
/// is made.</param>
/// <returns>Returns true if an output port is required, or false
/// otherwise.</returns>
///
public static bool DoesStatementRequireOutputPort(
IEnumerable<IEnumerable<string>> statementVariables, int index)
{
if (statementVariables == null)
throw new ArgumentNullException("statementVariables");
int statementCount = statementVariables.Count();
if (statementCount <= 0)
return false;
if (index < 0 || (index >= statementCount))
throw new IndexOutOfRangeException("index");
var currentVariables = statementVariables.ElementAt(index);
for (int stmt = index + 1; stmt < statementCount; stmt++)
{
var variables = statementVariables.ElementAt(stmt);
foreach (var cv in currentVariables)
{
if (variables.Contains(cv))
return false;
}
}
return true;
}
示例13: FindYieldMm
public static double FindYieldMm(double y, IEnumerable<Object> otherParams)
{
double P = (double) otherParams.ElementAt(0);
double C = (double) otherParams.ElementAt(1);
long M = (long) otherParams.ElementAt(2);
long littleM = (long) otherParams.ElementAt(3);
return AnnuityWithCandyandMm(C, y, M, littleM) - P;
}
示例14: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 1);
if (arguments.Count() == 1 && arguments.ElementAt(0).Value != null)
{
return CreateResult((arguments.ElementAt(0).Value is string), DataType.Boolean);
}
return CreateResult(false, DataType.Boolean);
}
示例15: Execute
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 3);
var condition = ArgToBool(arguments, 0);
var firstStatement = arguments.ElementAt(1).Value;
var secondStatement = arguments.ElementAt(2).Value;
var factory = new CompileResultFactory();
return condition ? factory.Create(firstStatement) : factory.Create(secondStatement);
}