Skip to content

Instantly share code, notes, and snippets.

View peterthorsteinson's full-sized avatar

Peter Thorsteinson peterthorsteinson

View GitHub Profile
using System;
using System.Text;
namespace TicTacToe_OO // object oriented implementation of tic tac toe
{
class Program
{
static void Main()
{
while (true)
using System;
class Program
{
static void Main(string[] args)
{
Vector2D v1 = new Vector2D(3, 4);
Console.WriteLine(v1);
Vector2D v2;
v2.x = 5;
using System;
using System.Reflection;
class Program
{
static void Main()
{
Console.Write("Enter name of method to be called (Method1 or Method2): ");
string methodName = Console.ReadLine();
MethodInfo methodInfo = typeof(Program).GetMethod(methodName);
using System;
namespace TicTacToeHumanVsMachineBruteForce
{
class Program
{
static char[] cells;
static Random rand = new Random();
static void Main()
{
int numberXWins = 0;
// Output:
// First 10 fibonacci numbers:
// 0 1 1 2 3 5 8 13 21 34
class First10FibonacciNumbers
{
static void Main()
{
int previous = 0;
int current = 1;
Here are two programs (client and server) that talk via tcp/ip over a socket connection.
1. Run the server side program first and note the ip address of the machine that it is running on.
2. Then run the client and enter the ip address of the server.
3. Finally enter a message and hit enter. The message is sent to the server, reversed, and then sent back to the client.
///////////////////
// TCP Client
using System;
using System.Net.Sockets;
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Thread[] threadArray = new Thread[8];
(threadArray[0] = new Thread(ThreadFunc)).Start(ConsoleColor.Red);
(threadArray[0] = new Thread(ThreadFunc)).Start(ConsoleColor.Yellow);
(threadArray[0] = new Thread(ThreadFunc)).Start(ConsoleColor.Magenta);
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Pig Dice");
Game game = new Game();
game.Play();
}
using System;
class Program
{
static void Main()
{
for (int i = 0; i < 20; i++)
{
object value = GetValueFromSomewhere();
switch (value)
{
using System;
class Program
{
static void Main()
{
int num = 10;
Console.WriteLine(AddUpToLoop(num));
Console.WriteLine(AddUpToRecursive(num, 0));
Func<int, int, int> AddUpToLambda = null;
AddUpToLambda = (num, sum) => { return num == 0 ? sum : AddUpToLambda(--num, sum + num + 1); };