This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class C | |
{ | |
static object M0<T>(IEnumerable<T> source) { | |
// linq с новой строки | |
var e1 = | |
from item in source | |
select item.ToString(); | |
return e1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Method(Entity entity) { | |
if(entity == null) { | |
throw new ArgumentNullException(nameof(entity)); | |
} else if(entity.Some.Property > 0) { | |
throw new ArgumentException(stringanize(entity.Some.Property > 0), nameof(entity)); | |
}//if | |
// "stringanize" makes a string from an expression | |
// and when we are renamed "Some" or "Property" | |
// string is updated! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
static void Main() { | |
var x = DateTime.Now.Day > 10 ? 1 : new Program() ?? default(object); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Overload of Debug.Assert with detailMessageFormat does not supported | |
// Debug.Assert has an overload with detailMessageFormat parameter: https://msdn.microsoft.com/en-us/library/cc190597(v=vs.110).aspx. | |
// This overload does not supported by R#: | |
// * No syntax highlighting and no validation of format arguments | |
// * Code analysises does not recognize this calls (null check not works) | |
class Program | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
static class Program | |
{ | |
static void Add(IReadOnlyCollection<object> items) { } | |
static void Add(IEnumerable<IReadOnlyCollection<object>> items) { } | |
static void Main() { | |
var list = new List<object[]>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
static class Program | |
{ | |
static void Main(string[] args) { | |
var lengths = args.Select(item => item.Length); | |
// "lengths" can be enumerated a few times, depending on a size of "args". | |
var xxx = args.Select(item => lengths.Select(x => x)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
// ReSharper disable once CheckNamespace | |
class MultiDictionary<TKey, TValue> : Dictionary<TKey, IList<TValue>> | |
{ | |
public void Add(TKey key, params TValue[] values) { } | |
} | |
static class Program | |
{ |
OlderNewer