Quote:
Originally Posted by amigo1
Code:
class mainclass{
void Main()
{
int ii =1; // perfectly working
for (int a =0 ; a<11 ; a++) // perfectly working
Console.WriteLine(ii++); // perfectly working
}
}
class itr
{
int i =1;
public int meth(){
for (int a =0 ; a<9 ; a++)
Console.WriteLine(i++);
}
}
error :
not all code paths return a value -- why and what this means?
================================================== ============================
|
The method meth is declared to return an int, and it doesn't return anything. Such a method must be declared of type void.
Quote:
Originally Posted by amigo1
Code:
class mainclass{
void Main()
{
int ii =1; // perfectly working
for (int a =0 ; a<11 ; a++) // perfectly working
Console.WriteLine(ii++); // perfectly working
}
}
class itr
{
int i =1;
public void meth(){
for (int a =0 ; a<9 ; a++)
Console.WriteLine(i++);
}
}
o/p
the above code does compile to give an output of the previous
loop i.e., for the a<11 part
the lower loop is not taken into account --- why
|
The method meth is never invoked. The Main method is the entry point in the application and is invoked. You need to instantiate an object of itr, and invoke the meth method.
Hope this helps.