Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Re-entrant implicit operator
Message
De
08/08/2016 05:34:51
 
 
À
08/08/2016 03:42:22
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01639212
Message ID:
01639215
Vues:
53
>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
		}
	}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform