using System;
class Program
{
static void Main()
{
// addition of two numbers
int a, b, sum;
Console.WriteLine("Enter the value of a:");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the value of b:");
b = int.Parse(Console.ReadLine());
sum = a + b;
Console.WriteLine("The sum of {0} & {1} is {2}",a,b, sum);
Console.ReadLine();
}
}
|
Output |
using System;
class Program
{
static void Main()
{
// how to print data types from variables
var i = 10;
Console.WriteLine(i.GetType());
var k = 23.1565;
Console.WriteLine(k.GetType());
var s = "panduraju";
Console.WriteLine(s.GetType());
var m = 3.156f;
Console.WriteLine(m.GetType());
var n = 3.14m;
Console.WriteLine(n.GetType());
Console.ReadLine();
}
}
|
Output |
using System;
class Program
{
static void Main()
{
//converting char to int
int i;
Console.WriteLine("Enter any Number:");
i = int.Parse(Console.ReadLine());
char c = Convert.ToChar(i);
Console.WriteLine(c);
Console.ReadLine();
//converting int to char
char k;
Console.WriteLine("Enter any Char:");
k = char.Parse(Console.ReadLine());
int m = Convert.ToInt32(k);
Console.WriteLine(m);
Console.ReadLine();
}
}
|
output |
using System;
class Program
{
static void Main()
{
//converting char to int
int i;
Console.WriteLine("Enter any Number:");
i = int.Parse(Console.ReadLine());
char c = Convert.ToChar(i);
Console.WriteLine(c);
Console.ReadLine();
//converting int to char
char k;
Console.WriteLine("Enter any Char:");
k = char.Parse(Console.ReadLine());
int m = Convert.ToInt32(k);
Console.WriteLine(m);
Console.ReadLine();
}
}
|
output |