Created
August 5, 2019 09:22
-
-
Save Tricky1975/3ec98beeed1ec29e8acf5af1d1cb6b64 to your computer and use it in GitHub Desktop.
Study how to make a class myself handling indexes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This was a study source on how to do indexes of my own in C#. | |
This study can really broaden my views on a few things in C#, and maybe also help me to get rid of a few issues I'm currently suffering in C# | |
*/ | |
using System; | |
class test { | |
public string this[string key] { | |
get { | |
switch(key){ | |
case "Dog": return "Woof!"; | |
case "Cat": return "Meow!"; | |
case "Bird": return "Tweet!"; | |
case "Cow": return "Moo!"; | |
default: return "Sorry, I don't know that one!"; | |
} | |
} | |
set { | |
Console.WriteLine($"And why must I change anything about your f*ing {key}?"); | |
} | |
} | |
} | |
public class Program | |
{ | |
static void p(string a) => Console.WriteLine(a); | |
public static void Main(){ | |
var t = new test(); | |
p(t["Bird"]); | |
p(t["Dog"]); | |
t["car"]="LALALA!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment