Skip to content

Instantly share code, notes, and snippets.

@miteshsureja
miteshsureja / Program.cs
Created March 8, 2017 13:53
How to cancel a Parallel.For and Parallel.Foreach loop – Task Parallel Library
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System;
using System.Threading.Tasks;
using System.Threading;
namespace ParallelFor
{
@miteshsureja
miteshsureja / FileDetails.cs
Created March 8, 2017 14:06
How to find and delete duplicate files from directory using C# code?
using System;
namespace DuplicateFileFinder
{
public class FileDetails
{
public string FileName { get; set; }
public string FileHash { get; set; }
}
}
@miteshsureja
miteshsureja / Program.cs
Created March 8, 2017 14:20
How to handle exception in Parallel.For and Parallel.Foreach loop? – Task Parallel Library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Concurrent;
namespace ParallelFor
{
class Program
{
static void Main(string[] args)
@miteshsureja
miteshsureja / Approver.cs
Created March 13, 2017 05:44
Chain of Responsibility design pattern example
namespace ChainOfResponsibility
{
//Handler class
public abstract class Approver
{
public abstract void HandleRequest(int requestAmount);
protected Approver NextApprover;
public void SetNextApprover(Approver approver)
{
NextApprover = approver;
@miteshsureja
miteshsureja / ParallelInvoke
Created April 30, 2017 14:09
Parallel.Invoke
namespace ParallelInvoke
{
using System.Threading;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
Parallel.Invoke(() =>
{
@miteshsureja
miteshsureja / BuyCommand.cs
Created May 1, 2017 12:46
Command Pattern
//Concrete Command class
public class BuyCommand : ICommand
{
private Product Product;
public string Name
{
get
{
return "Buy Command";
}
@miteshsureja
miteshsureja / Context.cs
Created May 10, 2017 14:41
Interpreter Design Pattern
//Context class
public class Context
{
public int Input { get; set; }
public Context(int inputValue)
{
Input = inputValue;
}
}
@miteshsureja
miteshsureja / Program.cs
Created May 21, 2017 13:00
Display Prime Numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RandomNumbers
{
class Program
{
@miteshsureja
miteshsureja / Program.cs
Created May 21, 2017 13:04
Find Max and Min value from List
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RandomNumbers
{
class Program
{
@miteshsureja
miteshsureja / Program.cs
Created May 21, 2017 13:11
Program to display series - 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RandomNumbers
{
class Program
{