0% found this document useful (0 votes)
5 views

C#3

Uploaded by

rupams2024
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)
5 views

C#3

Uploaded by

rupams2024
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
You are on page 1/ 2

<Query Kind="Statements" />

byte a = 45;
sbyte b = Convert.ToSByte(a);
Console.WriteLine(b);

double a = 1.0;
double b = 3.0;
Console.WriteLine(a / b);

decimal c = 1.0M;
decimal d = 3.0M;
Console.WriteLine(c / d);

float e = 1.0f;
float f = 3.0f;
Console.WriteLine(e / f);

float radius = 16.567f;


double radius1 = 16.567;
decimal radius2 = 16.567m;
double Area = (System.Math.PI) * radius * radius;
double Area1 = (System.Math.PI) * radius1 * radius1;
decimal = decimal * decimal.....any other casting is required
decimal Area2 = Convert.ToDecimal(System.Math.PI) * radius2 * radius2;
Console.WriteLine($"float Area of Circle is {Area}");
Console.WriteLine($"double Area of Circle is {Area1}");
Console.WriteLine($"decimal Area of Circle is {Area2}");

int a = 7;
int b = a;
int c = b++;//assign 7 to c then incremented ...now b= 8
int d = a + b * c;//8+1 =9
int e = a >= 100 ? b : c/10 ;
string s = "string literal";
char l = s[s.Length-1];
var numbers = new List<int>(new[] { 1, 2, 3 });
b = numbers.FindLast(n => n > 1);
Console.Write($"{b}");

var r = 2.3;
var message = $"The area of a circle with radius {r} is {Math.PI * r *r:F3}.";
Console.WriteLine(message);

int[] numbers = { 2, 3, 4, 5 };
var maximumSquare = numbers.Max(x => x * x);
Console.WriteLine(maximumSquare);

var scores = new[] { 90, 97, 78, 68, 85 };


IEnumerable<int> highScoresQuery =
from score in scores
where score > 80
orderby score descending
select score;
Console.WriteLine(string.Join(" ", highScoresQuery));

int x= 5;
int y= 3;
Console.Write($"{x|y}");

Console.WriteLine($"{13/-5}");

int[] arr = new int[5]{23,5,12,56,63};


int margin = 1;
int[] inner = arr[margin..^margin];
foreach(var i in inner)
{
Console.Write($"{i} "); // output: 10 20 30 40
}

You might also like