I am absolutely new to C# , reading the Book , Beginning Visual C# 2005 ,byKarli Watsonet al. , Wrox Press . Using Visual Studio 2005 .
Okay , I was practicing some of the concepts from Functions chapter and i faced a wierd error.
This the code which is running OK now.
namespace Ch06Ex01
{
class Program
{
static void Write()
{
Console.WriteLine("This is my first C# Function Code");
}
static sbyte AddTwo()
{
Console.WriteLine("Adding two numbers and returning the value");
sbyte testNum = 2 + 5;
return testNum;
}
static double AddTwoNum(double Num1,double Num2)
{
return Num1+Num2;
}
static void Main(string[] args)
{
Write();
Console.WriteLine("{0}",AddTwo());
Console.WriteLine("Enter two numbers two be added by a test function :");
double Num1,Num2;
Num1 = Convert.ToDouble(Console.ReadLine());
Num2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The Addtion of abive 2 numbers r = {0}", AddTwoNum(Num1,Num2));
Console.ReadKey();
}
}
}
which is fine and dandy . But the problem crops in when in the function static double AddTwoNum(double Num1,double Num2) i use byte inplace of double .
static byte AddTwoNum(byte Num1,byte Num2)
{
return Num1+Num2;
}
// ..Same Code...
// ..Same Code...
Byte Num1,Num2;
Num1 = Convert.ToByte(Console.ReadLine());
Num2 = Convert.ToByte(Console.ReadLine());
Console.WriteLine("The Addtion of abive 2 numbers r = {0}", AddTwoNum(Num1,Num2));
//..Same Code..
The error is shown @ return Num1+Num2; , a blue curly wavy underlined , when cursor is brought, a message pops up
Cannot Implicitly convert type 'int' to 'byte'. An Explicit Conversion exists (Are you missing a cast ?)
WHY ? :( Please someone come to my rescue ?