Skip to content

Instantly share code, notes, and snippets.

static class C
{
static object M0<T>(IEnumerable<T> source) {
// linq с новой строки
var e1 =
from item in source
select item.ToString();
return e1;
}
using System.Collections.Generic;
using System.Collections.ObjectModel;
internal static class Program
{
private static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key) { return default(TValue); }
private static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> source, TKey key) { return default(TValue); }
private static void Main() {
var dictionary = new Dictionary<int, int>();
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
namespace Xxx.ComponentModel
{
public abstract class CustomPropertyDescriptor : PropertyDescriptor
{
protected CustomPropertyDescriptor(MemberDescriptor descr) : base(descr) { }
@ViIvanov
ViIvanov / Count(), Any().cs
Last active January 4, 2016 14:58
Count(), Any()
void M<T>(ICollection<T> source) {
var a = source.Any(); // OK, statically known, that source is ICollection<T> and call is optimized
var b = source.Count(); // Warning, source.Count is better
}
bool M1<T>(IEnumerable<T> source) {
return source.Any(); // OK - one iteration in a worst case
}
int M1<T>(IEnumerable<T> source) {