Goto and generic methods. How can I make this work? Why the error?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello!
I posted this before at http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9e61306e-debe-41bd-a9ae-d85ac8995a6c
How can I add 2 numbers without knowing the type?
Im posting this again because this is another question.
This is my code:

<div style="color:black; background-color:white
<pre><span style="color:blue <span style="white-space:pre try
{
<span style="color:blue goto decimalL;

doubleL:
{
Console.WriteLine(<span style="color:#a31515 "Escreva 2 nÃmeros");
<span style="color:blue double x = <span style="color:blue double.Parse(Console.ReadLine());
<span style="color:blue double y = <span style="color:blue double.Parse(Console.ReadLine());
Console.WriteLine(<span style="color:#a31515 "{0} + {1} = {2}n", x, y, Calc.Adic<<span style="color:blue double>(x, y));
}

decimalL:
{
Console.WriteLine(<span style="color:#a31515 "Escreva 2 nÃmeros");
<span style="color:blue decimal a = <span style="color:blue decimal.Parse(Console.ReadLine());
<span style="color:blue decimal b = <span style="color:blue decimal.Parse(Console.ReadLine());
Console.WriteLine(<span style="color:#a31515 "{0} + {1} = {2}n", a, b, Calc.Adic<<span style="color:blue decimal>(a, b));
}
}

<span style="color:blue catch(OverflowException)
{
<span style="color:blue goto doubleL;
}
[/code]

<br/>
<br/>

But I got an error and a warning (they are 100% unrelated to the generic method Adic):

Error 1<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
No such label doubleL within the scope of the goto statement<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
C:UsersjmcomputadorDocumentsVisual Studio 2010ProjectsCalcularTesteCalcularProgram.cs<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
200<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
25<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
TesteCalcular
<div style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; color:#333333; font-size:13px; line-height:16px; text-align:left; padding:0px; margin:0px; border:0px initial initial
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
Warning<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
2<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
This label has not been referenced<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
C:UsersjmcomputadorDocumentsVisual Studio 2010ProjectsCalcularTesteCalcularProgram.cs<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
181<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
21<span style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; white-space:pre; padding:0px; margin:0px; border:0px initial initial
TesteCalcular
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial


<div style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; color:#333333; font-size:13px; line-height:16px; text-align:left; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Whats wrong?
<
JoÃo Miguel<br/>
<br/>

View the full article
 


Write your reply...
Back
Top