using System;
// csc while_loop_2.cs
class whileloop
{
public whileloop()
{ Console.WriteLine( "constructor evolved");}
~whileloop()
{ Console.WriteLine("destrctor evoked");}
public int wl(int n)
{
int i = 0;
while (i < n)
{
Console.Write("L="+ i + ",");
i++;
}
Console.WriteLine();
return i;
}
}
class test
{
static void Main()
{
whileloop w = new whileloop();
Console.Write("Enter a number :" );
string str;
str= Console.ReadLine();
try
{
//try block if correct wont show
int num = Int32.Parse(str);
w.wl(num);
Console.WriteLine("OK, carried On");
}
catch(Exception ex)
{
Console.WriteLine("looks like you missed something :"+
str + " you may use ex to complete result" );
}
}
}
|