Created
November 30, 2010 20:48
-
-
Save dylanbeattie/722373 to your computer and use it in GitHub Desktop.
How to make C# look like Basic, #1 - DIM statements
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
using System; | |
using System.Collections.Generic; | |
public class DIM { | |
private string contents; | |
private DIM(string contents) { | |
this.contents = contents; | |
} | |
public static implicit operator DIM(int x) { | |
return(new DIM(x.ToString())); | |
} | |
public static implicit operator DIM(string s) { | |
return(new DIM(s)); | |
} | |
public static DIM operator +(DIM a, DIM b) { | |
int aOut, bOut; | |
if (Int32.TryParse(a.contents, out aOut) && Int32.TryParse(b.contents, out bOut)) { | |
return(new DIM((aOut + bOut).ToString())); | |
} | |
return(new DIM(a.ToString() + b.ToString())); | |
} | |
public override string ToString() { | |
return(contents); | |
} | |
} | |
public class MyClass | |
{ | |
public static void Main() | |
{ | |
DIM x = 5; | |
DIM y = 10; | |
Console.WriteLine(x + y); | |
DIM foo = 12; | |
DIM bar = "shark"; | |
Console.WriteLine(foo + bar); | |
Console.ReadKey(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment