0% found this document useful (0 votes)
10 views4 pages

C# Programming Basics and Examples

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

C# Programming Basics and Examples

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// See [Link]

ms/new-console-template for more information


using System;
public class Sample
{
public static void Main(string[] args)
{
int a = 1;
int b = 2;
int c = a + b;
c = a * b;
c = a / b;
c = a % b;
c = a + b;
[Link](c);
for (int i = 0; i < c; i++)
{
[Link](i);
}
[Link]($"{[Link]}");
while (c > 0)
{
[Link](c);
c--;
}
int x = 10;
int y = x++;
[Link]("a={0}, b{1}", x, y);

//unboxing

object aa = 10;
int bb = (int)aa;
[Link]("a={0}", bb);
//boxing
int aaa = 10;
object bbb = aaa;

[Link]("Hello, World!");
[Link]("first num:?");
var num = [Link]([Link]());
[Link]("second num:?");
int num2 = Convert.ToInt32([Link]());

var date = [Link];


[Link]($"{[Link]}first: {num},
{[Link]}second:{num2}, {[Link]}date{date}on !");
String ab = [Link](num2);
[Link]($"a datatype is:{ab} : "+ [Link]());
[Link]($"num datatype is:{ num} : "+[Link]());
[Link]("a={0},b={1},c={2}", num, num2, a);

//escape sequence
String name = "hello1 \n hello2";
String name1 = "\"hello\"";
String name2 = "c:\\downloads\\program";
[Link](name2);
//c:\downloads\program
String name3 = @"c:\\downloads\\program";
// c:\\downloads\\program
[Link](name3);
[Link](name1 +"\n"+ name);
//o/p : name1="hello", name= hello1
//hello2
}
}

// See [Link] for more information


using System;
public class LowerorUpper
{
public static void Main(string[] args)
{
//EXPLICIT TYPE CATSING
float f = 28497473498714987.324f;
int i = (int)f;
[Link](i);//-2147483648
// int j = Covert.ToInt32(f);
//ERROR

int ii = 212;
float ff = (float)i;//-2.1474836E+09
[Link](ff);

//IMPLICIT TYPE CASTING


float fff = 212.323;
int a=(int )fff;
[Link](a);

}
}

using System;
public class LowerorUpper
{
public static void Main(string[] args)
{
String s = "56365hgd";
bool b= [Link](s, out int result);
[Link](b);//false
[Link](result);
//NULL COLIZING OPERATOR ='?'
int? x =null;
//int? y = x;
[Link](x??20);
//[Link]("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 = [Link](1,101);
while (i != target && i>0 && i<101 )
{
count++;
[Link]("guess the num " + count+ "time\n");
i=[Link]([Link]());
if(count== 5)
{
break;
}
else if (i == target)
{
break;
}
else if (i < target)
{
[Link]("less than target");
}
else
{
[Link]("greater than target");
}
}
[Link]("target achived target is :" + target + "count is :" +
count);

}
}

//LEAP YEAR

using System;
public class guess
{
public static void Main(string[] args)
{
[Link]("enter a year");
int yr = [Link]([Link]());
int leap = yr % 4;
int lp = yr % 100;
int l = yr % 400;
if (leap == 0 && lp != 0 || l==0)
[Link]("leap year");
else
[Link]("not a leap");
}
}

using System;
public class Guess
{
public static void Main(string[] args)
{
[Link]("enter the wieght");
float w = [Link]([Link]());
[Link]("enter the height");
float h = (float)[Link]([Link]());
h = (float)(h * 0.3048);
float bmi = w / (h * h);
[Link]("BMI of the given person with wieght : "
+ w + ",height : " + h + " BMI is ={0}" +
bmi,bmi);
if (bmi < 18.5)
[Link]("under weight");
else if (bmi > 18.5 && bmi < 24.9)
[Link]("healthy weight");
else if (bmi > 30)
[Link]("obesity");
else
[Link]("over weight");
}
}

// See [Link] for more information


using System;

public class Guess


{
public static void Main(string[] args)
{
bool upper = false;
bool lower = false;
bool num = false;
bool spl = false;
[Link]("enter the password");
String str = [Link]();

for (int i = 0; i < [Link] - 1; i++)


{
if ([Link](str[i]))
upper = true;
else if ([Link](str[i]))
lower = true;
else if ([Link](str[i]))
num = true;
else if (str[i] == '+'|| str[i] =='-'|| str[i] =='_'|| str[i] =='='||
str[i] =='@'|| str[i] =='$'||str[i] =='.')
spl = true;
}
if (upper && lower && num && spl&&[Link]>8)
[Link]("strong password");
else if (upper && lower && num)
[Link]("moderate password");
else
[Link]("weak password");
}
}

You might also like