Custom Class Type Casting (to string)

How can I format a typecasting function in my custom class so that when I pass it off as another parameter type, say string, it uses the function to return an instance of the new type? I’m guessing it is something like

static public string…something something?

Edit:
The custom class is essentially a string holder, with a name and other flags

	public class Datum
	{
		public string name;
		public string value;
		public string type;

this has a few unnecessary variables omitted.
It would be great if I could use simplified code to do things like the following:
Datum datumExample = “null”; // Every variable is initialized to the string “null”

// or
void aFunction(Datum a = "null"){};
aFunction();
// or
void aFunction(string a = "null"){};
aFunction(datumExample); // Where datumExample automatically returns it's
// .value variable

If you do not inherit MonoBehavior, than you can add a simple default constructor, or parameter constructor:

public class Datum
{
	public string name;
	public string val;
	public string type;

	public Datum() {
		name = "null";
		val = "null";
		type = "null";
	}
}

//or
public class Datum
{
	public string name;
	public string val;
	public string type;

	public Datum(string blee) {
		name = blee;
		val = blee;
		type = blee;
	}
}

Then you can do Datum blou = new Datum(); or Datum blaa = new Datum("null");

In this case:

void aFunction(string a = "null"){};
 aFunction(datumExample); // Where datumExample automatically returns it's
 // .value variable

Why not aFunction(datumExample.value); if it is public, or a simple getter aFunction(datumExample.getValue()); if it is private?

KISS :slight_smile: Hope this helps.

[edit] I agree with @NewPath that using “null” is a little strange…