本文整理汇总了C#中this.Count方法的典型用法代码示例。如果您正苦于以下问题:C# this.Count方法的具体用法?C# this.Count怎么用?C# this.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AllInOneTrend
public static bool AllInOneTrend(this IEnumerable<Quote> list)
{
return
list.Skip(list.Count() > 1 ? 1 : 0).Select((q, i) => new { q, i }).All(x => x.q.Close > list.ElementAt(x.i).Close)
||
list.Skip(list.Count() > 1 ? 1 : 0).Select((q, i) => new { q, i }).All(x => x.q.Close < list.ElementAt(x.i).Close);
}
示例2: CapitalizeWord
public static string CapitalizeWord(this string word)
{
char[] tempArray = word.ToCharArray();
// capitalize first char if not a number
// if number then probably a numbered book
int bookNumber;
if (int.TryParse(Convert.ToString(tempArray[0]), out bookNumber)) // first char is number
{
// assume spot 2 is what needs capitalized.
tempArray[2] = char.ToUpper(tempArray[2]);
for (int i = 3; i < word.Count(); i++)
{
tempArray[i] = char.ToLower(tempArray[i]);
}
}
else // first char is not number so capitalize it
{
tempArray[0] = char.ToUpper(tempArray[0]);
for (int i = 1; i < word.Count(); i++)
{
tempArray[i] = char.ToLower(tempArray[i]);
}
}
string tempString = "";
foreach (char i in tempArray)
{
tempString += i;
}
return tempString;
}
示例3: CreateInstallment
public static ViewPaymentInstallmentItems[] CreateInstallment(this IEnumerable<Installment> input)
{
string numberFormat = ConfigurationManager.Format.NUMBER_FORMAT;
var InstallmentItems = new ViewPaymentInstallmentItems[0];
if (input.Count() > 0)
{
InstallmentItems = new ViewPaymentInstallmentItems[input.Count()];
var installment = input.ToArray();
for (int i = 0; i < installment.Count(); i++)
{
InstallmentItems[i] = new ViewPaymentInstallmentItems
{
No = (i + 1).ToString(numberFormat),
InstallmentId = installment[i].Id.ToString("0000000000"),
InstalledDate = installment[i].InstallmentDate.ToString(ConfigurationManager.Format.Date_Format),
InstalledBy = installment[i].InstallmentBy,
Method = installment[i].Method,
Amount = installment[i].Amount.ToString(ConfigurationManager.Format.Decimal_Format),
};
}
}
return InstallmentItems;
}
示例4: IsEquivalentTo
public static bool IsEquivalentTo(this IEnumerable<int> first, IEnumerable<int> second)
{
if (first == null && second == null)
{
return true;
}
if (first == null || second == null)
{
return false;
}
if (first.Count() != second.Count())
{
return false;
}
for (var i = 0; i < first.Count(); i++)
{
if (first.ElementAt(i) != second.ElementAt(i))
{
return false;
}
}
return true;
}
示例5: AddConjunctions
/// <summary>
/// Add conjunctions, such as commas "," and "ands" to
/// concatenate the given phrases into a sentence.
/// </summary>
/// <param name="effectSpans">
/// The lists of lists of <see cref="EffectSpan"/> to
/// add conjunctions to. This cannot be null and no element
/// within hte list can be null.
/// </param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="effectSpans"/> cannot be null and no
/// element within it can be null.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="effectSpans"/> cannot be empty.
/// </exception>
public static IEnumerable<EffectSpan> AddConjunctions(this IList<List<EffectSpan>> effectSpans)
{
if (effectSpans == null)
{
throw new ArgumentNullException("effectSpans");
}
if (!effectSpans.Any())
{
throw new ArgumentException("Cannot be empty", "effectSpans");
}
if (effectSpans.Any(x => x == null))
{
throw new ArgumentNullException("effectSpans");
}
List<EffectSpan> result;
result = new List<EffectSpan>();
for (int i = 0; i < effectSpans.Count(); i++)
{
result.AddRange(effectSpans[i]);
if (i < effectSpans.Count() - 2)
{
result.Add(new EffectSpan(", "));
}
else if (i == effectSpans.Count() - 2)
{
result.Add(new EffectSpan(" and "));
}
}
return result;
}
示例6: SimpleMovingAverage
/// <summary>
/// Returns IEnumerable of SMA(x). First (period-1) values returns null value
/// </summary>
public static IEnumerable<decimal?> SimpleMovingAverage(this IEnumerable<decimal> values, int period)
{
Contract.Requires(values != null);
Contract.Requires(period >0 && period <= values.Count());
var result = Enumerable.Range(1 - period, values.Count()).Select(c => values.Skip(c).Take(period).Sum()/period);
return Enumerable.Range(0, period - 1).Select(i => null as decimal?).Concat(result.Skip(period - 1).Cast<decimal?>());
}
示例7: TypeSequenceIsAssignableFrom
public static bool TypeSequenceIsAssignableFrom(this IEnumerable<Type> source, IEnumerable<object> sequence)
{
var canCast = true;
if (source.Count() == sequence.Count())
{
if (source.Count() > 0)
{
var srcEnum = source.GetEnumerator();
var seqEnum = sequence.GetEnumerator();
do
{
if (seqEnum.Current == null)
{
continue;
}
canCast = srcEnum.Current.IsAssignableFrom(seqEnum.Current.GetType());
}
while (srcEnum.MoveNext() && seqEnum.MoveNext() && canCast);
}
}
else
{
canCast = false;
}
return canCast;
}
示例8: Mean
public static double Mean(this IEnumerable<double> source)
{
if (source.Count() < 1)
return 0.0;
double length = source.Count();
double sum = source.Sum();
return sum / length;
}
示例9: BranchShort
public static void BranchShort(this List<object> codeList, Code op, int label)
{
Debug.Assert((codeList.Count() - label) < SByte.MaxValue);
// +2, op code + address code, as backward jump start from first byte of the end of branch command with address
var address = (byte) -(codeList.Count() - label + 2);
codeList.Add(op);
codeList.Add(address);
}
示例10: ListEquals
public static bool ListEquals(this IEnumerable<Type> source, IEnumerable<Type> compare)
{
if (source.Count() != compare.Count())
return false;
for (var i = 0; i < source.Count(); i++)
if (source.ElementAt(i) != (compare.ElementAt(i)))
return false;
return true;
}
示例11: ToArrayOfVec3F
public static SbVec3f[] ToArrayOfVec3F(this List<Color> colors)
{
var vec = new SbVec3f[colors.Count()];
for (int i = 0; i < colors.Count(); i++)
{
vec[i] = colors[i].ConvertToVec3F();
}
return vec;
}
示例12: AddContextAccessor
public static IServiceCollection AddContextAccessor(this IServiceCollection self)
{
if (self.Count(x => x.ServiceType == typeof(IHttpContextAccessor)) == 0)
self.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
if (self.Count(x => x.ServiceType == typeof(IActionContextAccessor)) == 0)
self.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
return self;
}
示例13: ToStringSeparatedWithAnd
public static string ToStringSeparatedWithAnd(this List<string> input)
{
if (input.Any())
{
if (input.Count() == 1)
return input.First();
var first = input.Count() == 2 ? input.First() : string.Join(", ", input.Take(input.Count() - 1));
return string.Format("{0} and {1}", first, input.Last());
}
return string.Empty;
}
示例14: AllItemsAreEqual
/// <summary>
/// <paramref name="left"/>와 <paramref name="right"/> 시퀀스의 요소들이 모두 같은 지를 판단합니다.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool AllItemsAreEqual(this IEnumerable<ITimePeriod> left, IEnumerable<ITimePeriod> right) {
if(left.Count() != right.Count())
return false;
var itemCount = left.Count();
for(var i = 0; i < itemCount; i++) {
if(Equals(left.ElementAt(i), right.ElementAt(i)) == false)
return false;
}
return true;
}
示例15: StandardDeviation
public static double StandardDeviation(this IEnumerable<double> values)
{
double ret = 0;
if (values.Count() > 0)
{
//Compute the Average
double avg = values.Average();
//Perform the Sum of (value-avg)_2_2
double sum = values.Sum(d => Math.Pow(d - avg, 2));
//Put it all together
ret = Math.Sqrt((sum) / (values.Count() - 1));
}
return ret;
}