Skip to content

Instantly share code, notes, and snippets.

View AndrewBarfield's full-sized avatar

Andrew Barfield AndrewBarfield

View GitHub Profile
@AndrewBarfield
AndrewBarfield / gist:2556747
Created April 30, 2012 09:11
C#: System.Collections.Generic: Working with a Generic SortedList
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericSortedList {
class Program {
static void Main(string[] args) {
// Creates and initializes a new SortedList.
@AndrewBarfield
AndrewBarfield / gist:2556751
Created April 30, 2012 09:13
C#: System.Collections.Hashtable
using System;
using System.Collections;
namespace HashtableExample {
class Program {
static void Main(string[] args) {
// Create a new hashtable
Hashtable genericDomains = new Hashtable();
@AndrewBarfield
AndrewBarfield / gist:2556767
Created April 30, 2012 09:16
C#: IComparable: Converting miles to kilometers
using System;
using System.Collections;
/*
* Sample Output
*
* 10 miles (16.09344 km)
* 86 miles (138.403584 km)
* 146 miles (234.964224 km)
* 214 miles (344.399616 km)
@AndrewBarfield
AndrewBarfield / gist:2556782
Created April 30, 2012 09:19
C#: IDisposable: Cleaning up managed and unmanaged resources
public class MyResource : IDisposable {
// Pointer to an external unmanaged resource.
private IntPtr handle;
// Other managed resource this class uses.
private Component component = new Component();
// Track whether Dispose has been called.
private bool disposed = false;
@AndrewBarfield
AndrewBarfield / gist:2556793
Created April 30, 2012 09:23
C#: System.Collections.IEnumerable: Custom Iterator Example
using System;
namespace IteratorsExample {
class Program {
static void Main(string[] args) {
// Create an instance of the collection class
EvenIntegers ei = new EvenIntegers();
// Iterate with foreach
foreach ( int num in ei ) {
@AndrewBarfield
AndrewBarfield / gist:2556878
Created April 30, 2012 09:39
C#: LINQ: How to construct an XML element
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace LINQExample {
class Program {
static void Main() {
var e = new XElement( "Person",
@AndrewBarfield
AndrewBarfield / gist:2556924
Created April 30, 2012 09:49
C#: How to perform Numerical Integration
using System;
namespace NumericalIntegration {
class Program {
static void Main(string[] args) {
int iterations = 100000;
double x, start, end, dist, sum = 0, sumT = 0;
Console.Write( "Input range start: " );
start = double.Parse( Console.ReadLine() );
@AndrewBarfield
AndrewBarfield / gist:2556928
Created April 30, 2012 09:51
C#: Working with the Stack class
using System;
using System.Collections;
namespace StackExample {
class Program {
static void Main(string[] args) {
// Creates and initializes a new stack
Stack stackColl = new Stack();
@AndrewBarfield
AndrewBarfield / Output.txt
Created April 30, 2012 10:18
C#: Calculating machine epsilon for a Float and Double
CSC 340 Scientific Computing
Machine Epsilon Homework
Andrew M. Barfield
Wednesday, January 14, 2009
3:15:29 PM
Float:
01) 0.5
02) 0.25
@AndrewBarfield
AndrewBarfield / Output.txt
Created April 30, 2012 10:27
C#: Calculate the Exponential Function exp(x) using Taylor Expansion
CSC 340 Scientific Computing
Calculate exp(3.7) using Taylor's Expansion
Andrew M. Barfield
Thursday, January 15, 2009
1:56:36 PM
Answer calculated in 29 iterations.
exp(3.7) = 40.447