Sample
Sample
//unboxing
object aa = 10;
int bb = (int)aa;
Console.WriteLine("a={0}", bb);
//boxing
int aaa = 10;
object bbb = aaa;
System.Console.WriteLine("Hello, World!");
Console.WriteLine("first num:?");
var num = int.Parse(Console.ReadLine());
Console.WriteLine("second num:?");
int num2 = Convert.ToInt32(Console.ReadLine());
//escape sequence
String name = "hello1 \n hello2";
String name1 = "\"hello\"";
String name2 = "c:\\downloads\\program";
Console.WriteLine(name2);
//c:\downloads\program
String name3 = @"c:\\downloads\\program";
// c:\\downloads\\program
Console.WriteLine(name3);
Console.WriteLine(name1 +"\n"+ name);
//o/p : name1="hello", name= hello1
//hello2
}
}
int ii = 212;
float ff = (float)i;//-2.1474836E+09
Console.WriteLine(ff);
}
}
using System;
public class LowerorUpper
{
public static void Main(string[] args)
{
String s = "56365hgd";
bool b= int.TryParse(s, out int result);
Console.WriteLine(b);//false
Console.WriteLine(result);
//NULL COLIZING OPERATOR ='?'
int? x =null;
//int? y = x;
Console.WriteLine(x??20);
//Console.WriteLine("x is : " + y);
}
}
using System;
public class guess
{
public static void Main(string[] args)
{
int count = 0;
int target = 10;
Random ran = new Random();
int i = ran.Next(1,101);
while (i != target && i>0 && i<101 )
{
count++;
Console.WriteLine("guess the num " + count+ "time\n");
i=int.Parse(Console.ReadLine());
if(count== 5)
{
break;
}
else if (i == target)
{
break;
}
else if (i < target)
{
Console.WriteLine("less than target");
}
else
{
Console.WriteLine("greater than target");
}
}
Console.WriteLine("target achived target is :" + target + "count is :" +
count);
}
}
//LEAP YEAR
using System;
public class guess
{
public static void Main(string[] args)
{
Console.WriteLine("enter a year");
int yr = int.Parse(Console.ReadLine());
int leap = yr % 4;
int lp = yr % 100;
int l = yr % 400;
if (leap == 0 && lp != 0 || l==0)
Console.WriteLine("leap year");
else
Console.WriteLine("not a leap");
}
}
using System;
public class Guess
{
public static void Main(string[] args)
{
Console.Out.WriteLine("enter the wieght");
float w = float.Parse(Console.ReadLine());
Console.Out.WriteLine("enter the height");
float h = (float)Convert.ToDouble(Console.ReadLine());
h = (float)(h * 0.3048);
float bmi = w / (h * h);
Console.Out.WriteLine("BMI of the given person with wieght : "
+ w + ",height : " + h + " BMI is ={0}" +
bmi,bmi);
if (bmi < 18.5)
Console.Out.WriteLine("under weight");
else if (bmi > 18.5 && bmi < 24.9)
Console.Out.WriteLine("healthy weight");
else if (bmi > 30)
Console.Out.WriteLine("obesity");
else
Console.Out.WriteLine("over weight");
}
}