What is the type of the 'value' reserved word in C# properties -


I'm thinking how the 'value' keyword in the property takes up.

Such:

  public class test {string _numberAsString; Int _number = -1; Public Test () {} Public String Number Eststring {get {return_numberAsString; } Set {_numberAsString = value; }} Public Integer Number {Received {return int.Parse (_numberAsString); } Set {_number = value; }}} // somewhere in test t = new test (); T. Number = 5;  

Now, it does not compile, as I expected the value of the value is determined by the return type of property, is that correct? I could not find anything for that effect, perhaps it is very clear (I have not read language spec, maybe there is something in it).

I ask, because I want to set the property is a type which then changes into the recipient's type, I think that it does not really understand.

It seems that I have to get it by making some methods.

Yes, the value of 'value' is determined by the return type of property. What exactly are you trying to accomplish? Do you want to be able to set the number or number eststring for a valid value or you want to remove the result from any property?

If so, then you need to do something like this:

Public Class Exam {string _numberAsString; Int _number = -1; Public Test () {} Public String Number Eststring {get {return_numberAsString; } Set {_numberAsString = value; }} Public Integer Number {Received {return int.Parse (_numberAsString); } Set {_numberAsString = value.ToString (); }}}

This will allow you to do this:

  test t = new test (); T. Number = 5; Console.WriteLine (t.NumberAsString); // "5" T. Number Asset String = "5" should be printed; Console.WriteLine (t.Number); // should print "5"  

You can not get another set for such a property which are of different types. You have the only option which it has to be internally To be stored in one form and then either to get or set (or both) the conversion from one type to another.


Comments