Skip to content

Instantly share code, notes, and snippets.

@btjake
Last active December 15, 2015 11:39
Show Gist options
  • Save btjake/5254652 to your computer and use it in GitHub Desktop.
Save btjake/5254652 to your computer and use it in GitHub Desktop.
Optional in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OptionalParams
{
public class CoolKidsClass
{
List<int> numbers = new List<int>();
public string text = "";
public CoolKidsClass(string _text)
{
text = _text;
for (int i = 0; i < 100; i++)
{
numbers.Add(i);
}
}
}
}
instantiated in StaticMethod
instantiated in Main
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace OptionalParams
{
class Program
{
static void Main(string[] args)
{
StaticMethod();
StaticMethod(new CoolKidsClass("instantiated in Main"));
Console.ReadKey();
}
public static void StaticMethod(CoolKidsClass ckc = null)
{
if (ckc == null) ckc = new CoolKidsClass("instantiated in StaticMethod");
Console.WriteLine(ckc.text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment