Skip to content

Instantly share code, notes, and snippets.

View csdear's full-sized avatar

Stuart Dear csdear

View GitHub Profile
@csdear
csdear / List : Serialize - Deserialize to Binary Format
Created June 26, 2015 18:15
List : Serialize - Deserialize to Binary Format
/*
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
*/
[Serializable()]
public class Lizard
{
@csdear
csdear / Basic Constructor for get - set accessor initialization
Last active August 29, 2015 14:23
Basic Constructor for get / set accessor initialization
public class Lizard
{
public string Type { get; set;}
public int Number {get; set;}
public bool Health {get; set;}
public Lizard(string t, int n, bool h)
{
Type = t;
Number = n;
@csdear
csdear / List - No Duplicates, DISTINCT
Created June 1, 2015 21:33
List - No Duplicates, DISTINCT
//using System;
//using System.Collections.Generic;
//using System.Linq
//
class Program {
static void Main()
@csdear
csdear / List & Foreach - Basic, Anonymously Typed
Created June 1, 2015 21:28
List & Foreach - Basic, Anonymously Typed
//using System;
//using System.Collections.Generic;
//using System.Linq
//
class Program {
static void Main()
@csdear
csdear / List & Foreach - Basic, Strongly Typed
Created June 1, 2015 21:27
List & Foreach - Basic, Strongly Typed
//using System;
//using System.Collections.Generic;
//using System.Linq
//
class Program {
static void Main()
@csdear
csdear / List Concat
Created June 1, 2015 18:36
List Concat
//using System;
//using System.Collections.Generic;
//using System.Linq
//Concats two lists together, robot arms and robot legs into one list, 'resultlist'
class Program {
static void Main()
@csdear
csdear / Object Initialization With List Initializers
Created May 28, 2015 20:58
Object Initialization With List Initializers
//using System;
//using System.Collections.Generic;
//C# program that initializes Object Lists.
//Robot has two properties, a ID and a name.
//These
class Robot //Used in lists .. (remember this are object Properties so it is UPPER case.)
{
@csdear
csdear / Anonymous Type Verses Strongly Typed
Created May 27, 2015 21:59
Anonymous Type Verses Strongly Typed
// E.g., a strongly typed object versus using an anonymous type.
//A1. As a traditional strongly typed class and instance of that class.
public class Book
{
public int BookID { get; set; }
public string BookName { get; set; }
public string AuthorName { get; set; }
public string ISBN { get; set; }
}
@csdear
csdear / Anonymous Type with a Collection As A Property
Created May 27, 2015 21:57
Anonymous Type with a Collection As A Property
/*This is a demo of anonymous type "request" that uses standalone Properties
AND a Property which is a collection type, "Settings".
Also demo'd is a foreach statement, for iterating through a Anonymous Type's collection Property.
*/
class Program {
static void Main()
{
//Anonymous Object that also a list object as a property... Has a list object as a property.
var request = new { Id = 1, UserId = 1, Settings = new List<IdValuePair>() { new IdValuePair { Id = 5, Value = "5" } } };
@csdear
csdear / Anonymous Type Simple
Created May 27, 2015 21:53
Anonymous Type Simple
// Simple, Anonymou type
//lp- C# Program
class Program {
static void Main()
{
var v = new { Amount = 108, Message = "Hello" };
Console.WriteLine(v);