Skip to content

Instantly share code, notes, and snippets.

@sachintha81
sachintha81 / LoopEnum.cs
Last active Dec 6, 2019
Loop through Enum
View LoopEnum.cs
// Typed version
var values = Enum.GetValues(typeof(Foos)).Cast<Foos>();
// Helper function
public static class EnumUtil {
public static IEnumerable<T> GetValues<T>() {
return Enum.GetValues(typeof(T)).Cast<T>();
}
}
@sachintha81
sachintha81 / deleteall.bat
Created Jun 9, 2017
Batch script to delete all files in current and sub folders excluding certain extensions.
View deleteall.bat
@echo off
forfiles /s /c "cmd /c (if NOT @ext==\"bat\" del /s /q @path)"
@sachintha81
sachintha81 / TrueRandomNumbers.cs
Created Jan 30, 2017
C# True (almost) Random Number Generator
View TrueRandomNumbers.cs
//The following sample uses the Cryptography class to simulate the roll of a dice.
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
class RNGCSP
{
private static RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
@sachintha81
sachintha81 / FileHashRetriever.cs
Created Jan 23, 2017
C# - Retrieve MD5 Hash of a File
View FileHashRetriever.cs
using System;
using System.IO;
using System.Security.Cryptography;
namespace FileHashCompare
{
class Program
{
static void Main(string[] args)
{
@sachintha81
sachintha81 / DragDropToTextBox.cs
Created Jan 13, 2017
C# - Drag Drop a File/Folder into a TextBox
View DragDropToTextBox.cs
using System;
using System.Collections.Generic;
using System.Windows;
using System.Collections.ObjectModel;
namespace TextBoxDragDrop
{
public partial class TextBoxDragDrop : Window
{
private void txtPath_PreviewDragOver(object sender, DragEventArgs e)
@sachintha81
sachintha81 / ColorLibrary.cs
Created Jan 13, 2017
WPF + C# Color Handling
View ColorLibrary.cs
namespace ColorLibrary
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
@sachintha81
sachintha81 / IndentStringWithTabs.cs
Created Jan 13, 2017
Indenting C# String Data with Tabs
View IndentStringWithTabs.cs
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StringIndent
{
public class StringIndent
@sachintha81
sachintha81 / ColorCodeDGV.xaml
Last active Dec 18, 2019
WPF + C# : Display Data and Color Code a DataGrid using Binding
View ColorCodeDGV.xaml
<Window x:Class="ColorLibrary.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ColorLibrary"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="MainWindow" Height="500" Width="400">
<Window.Resources>
@sachintha81
sachintha81 / MoveListViewItems.cs
Created Jan 13, 2017
WPF + C# Move Multiple Items from one ListView to Another
View MoveListViewItems.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace ListViewOperations.SOURCE.GUI
{
public partial class ListViewOperations : Window
{
@sachintha81
sachintha81 / WPFMessengerClass.cs
Created Jan 13, 2017
Messenger Class for the WPF + MVVM Pattern
View WPFMessengerClass.cs
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MVVMMessenger
{
public class Messenger
You can’t perform that action at this time.