Code Snippets

This is just a list of the small code samples that I always seem to forget, and I use this page as a personal reference for those little code snippets.

string.Split

string[] values = delimited.Split(new string[] { “/” }, StringSplitOptions.RemoveEmptyEntries);

DateTime.ToString()

These are the custom date time formats that I like to use and always forget..

DateTime.Now.ToString(“dd-MMM-yyyy hh:mm:ss.fff tt”);

  • MMM – Three digit month
  • hh – 12 hour time
  • HH – 24 hour time
  • mm – lower case m’s for minutes
  • fff – milliseconds
  • tt – AM / PM

When using a date for a log entry timestamp I use:
DateTime.Now.ToString(“yyyy-MM-dd hh:mm:ss”);

Access the Registry

using Microsoft.Win32;
...
// This creates or opens
RegistryKey key = Registry.LocalMachine.CreateSubKey("\Sofware\YourApplication\YourKey");

SQL methods

  • newid() – generates a new uniqueidentifier (uuid or guid)
  • charindex(searchcriteria, stringtoSearch, [startPosition])
  • substring(stringToCheck, startingPos, Length)
  • replace( stringToCheck , searchValue , replacementValue )

  1. No comments yet.
  1. No trackbacks yet.