Skip to content

Making your own "int" or "string" class

Aidan Follestad

Asked Apr 5, 2010, 5:43 PM EDT1 answer
Share
LinkedInX
I disassembled the .NET 'System' DLL and looked at the source code for the variable classes (string, int, byte, etc.) to see if I could figure out how to make a class that could take on a value. I noticed that the "Int32" class inherits the following: IComparable, IFormattable, IConvertible, IComparable<int>, IEquatable<int>.

The String and Int32 classes are not inheritable, and I can't figure out what in these inherited interfaces allows the classes to hold a value. What I would want is something like this:

C#
public class MyVariable : //inherits here
{
     //Code in here that allows it to get/set the value
} 

public static class Main(string[] args)
{
     MyVariable a = "This is my own custom variable!";
     MyVariable b = 2976;

     if(a == "Hello") { }
     if(b = 10) { }
     Console.WriteLine(a.ToString());
     Console.WriteLine(a.ToString());
}

(I'VE FOUND ANSWER: http://msdn.microsoft.com/en-us/library/6fbs5e2h%28v=VS.80%29.aspx)

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.