public static int Min(this IEnumerable<int> ints)
{
return ints.Aggregate((min, next) => min <= next ? min : next);
}
This file contains hidden or 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.Diagnostics; | |
| using System.Linq; | |
| using System.Text; | |
| public class Program | |
| { | |
| public static string ReverseString(string input) | |
| { | |
| if (input == null) |
This file contains hidden or 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; | |
| namespace FuncOverloads | |
| { | |
| public class Program | |
| { | |
| public static void Main( string[] args ) | |
| { | |
| Func<int> funcReturnsInt = () => { return 0; }; |
This file contains hidden or 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
| public enum SocketStates | |
| { | |
| Unknown, | |
| Up, | |
| Down | |
| } | |
| public class SocketWatcher : IObservable<SocketStates>, IDisposable | |
| { | |
| private readonly BehaviorSubject<SocketStates> _socketState = new BehaviorSubject<SocketStates>(SocketStates.Unknown); |
This file contains hidden or 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
| public class SingletonObservable : IObservable<DateTime>, IDisposable | |
| { | |
| private readonly Subject<DateTime> _subject = new Subject<DateTime>(); | |
| private bool _isRunning = true; | |
| public SingletonObservable() | |
| { | |
| InstanceCount++; | |
| Task.Run( async () => |
I've always heard that one should not call overridable methods in constructors, and doing so will cause a violation during compilation. To understand why a build warning is generated, lets look at an example.
First, let me state something that we all should hopefully find reasonable. When instantiating an instance of a class, the first thing that should be called is the class' constructor. So assume we have a class that logs strings to a file:
public class FileLogger
{
private readonly string _logDirectory;
public FileLogger(string logDirectory)Coming from a background that was not heavy on callbacks, whenever I wanted to short-circuit a method I would simply "return".
For example:
public void Log(string data)
{
if (data == null)
return;
...
}
This file contains hidden or 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; | |
| using System.Linq; | |
| using System.Net; | |
| using System.Reactive.Linq; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| namespace Tests | |
| { |
NewerOlder