Skip to content

Instantly share code, notes, and snippets.

View Sheepings's full-sized avatar
🎯
Focusing

Sheepings Sheepings

🎯
Focusing
  • UK
View GitHub Profile
@Sheepings
Sheepings / Program.cs
Created July 17, 2020 20:09
How to work with arrays with null values
string[] lString = new string[] { "All", "Apples", null, null };
/* Using an enumerator to step through the array of strings where the values are not null */
IEnumerator enumerator = (from lValue in lString where lValue != null select lValue).ToArray().GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Current);
}
/* For each string in the array, select where the value is not null, and do something with the value */
@Sheepings
Sheepings / RemoveItemFromArray.cs
Created July 15, 2020 12:52
A snipped for removing items from an array
public class Student
{
public string Name { get; set; }
public enum Gender
{
Male, Female
}
public int Age { get; set; }
@Sheepings
Sheepings / Binding_INotifyPropertyChanged.xaml.cs
Created March 22, 2020 20:03
INotifyPropertyChanged With Bindings
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace WPFTestApp
{
public partial class Window1 : Window
{
@Sheepings
Sheepings / Program.cs
Created February 12, 2020 16:37
This program writes a log of JSON report files which logs file entries between the origin directory and a backup directory. If the file does not exist on a backup directory, it is then copied over from the source folder and the json file is marked with a bool state to indicate if the archive file exists.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
namespace TestConsoleApp
{
@Sheepings
Sheepings / WMI_GetDependentObjects.cs
Created January 12, 2020 15:10
This code will return the list of installed program names and the install path if it exists.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Management;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestCSharpApp
{
@Sheepings
Sheepings / GetInstalledApps.cs
Created January 9, 2020 22:56
Getting All Installed Programs From Windows Registry Using Multi-Threading
using Microsoft.Win32;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestCSharpApp
{
public partial class Form1 : Form
{
public Form1()
@Sheepings
Sheepings / TestExecutionContext.cs
Created December 15, 2019 14:25 — forked from azureskydiver/TestExecutionContext.cs
Execution Context not capturing thread id
using System;
using System.Text;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
public class Test
{
static ExecutionContext _ec;
@Sheepings
Sheepings / Form1.cs
Last active November 27, 2019 14:18
Iterate Recycle bin objects and return paths patterns names and addresses to a List<Tuple<string, string, string>>. Requires a reference to shell32.dll in system32 folder.
public List<Tuple<string, string, string>> rBinFiles = new List<Tuple<string, string, string>>();
private void Button1_Click(object sender, EventArgs e)
{
var recycleBin = @"C:\$Recycle.Bin";
DirectoryInfo rBinInfo = new DirectoryInfo(recycleBin);
GetBinFileNames();
foreach (List<Tuple<string, string, string>> t in GetBinFileNames())
{
t.ForEach((Tuple<string, string, string> name) =>
{
@Sheepings
Sheepings / Form1.cs
Created November 22, 2019 21:01
Quick script to read file contents to ArrayList and search the ArrayList for matching contents
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static readonly string FilePath = Path.Combine(Application.StartupPath, "txt1.txt");
private static readonly string ErrorLog = FilePath.Replace(Path.GetFileName(FilePath), "errorlog.log");
@Sheepings
Sheepings / GetPersonFromTextFile.cs
Last active November 27, 2019 00:29
This class creates a class of persons which is read from a text file. You can search the class for specific persons also.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static readonly string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "mytext.txt");
private void Button1_Click(object sender, EventArgs e)
{
using (FileStream reader = File.OpenRead(path))