Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Re-entrant implicit operator
Message
De
08/08/2016 05:55:11
 
 
À
08/08/2016 05:34:51
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01639212
Message ID:
01639216
Vues:
52
>>Interesting bit of bad code which the compiler does not catch and which causes stack overflow because it is re-entrant:
static void Main(string[] args)
>>        {
>>            Test test = "Hello World";
>>        }
>>
>>    public class Test
>>    {
>>        public static implicit operator Test(string s)
>>        {
>>            return s; // obviously wrong but compiles and is re-entrant when run
>>        }
>>    }
>
>I think the problem is that the operator does not return an instance of Test
>
>Maybe something like this
>
>	public class Test
>	{
>		public string Value { get; private set; }
>		public Test(string s)
>		{
>			this.Value = s;
>		}
>		public static implicit operator Test(string s)
>		{
>			return new Test(s); // obviously wrong but compiles and is re-entrant when run
>		}
>	}
>
Yea. I knew how it was supposed to be. Just surprised that my intial 'typo' was allowed and gave the results that it did.....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform