C# Basics
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello
{
class Program
{
static void Main(string[] args)
{
int har = 34;
/*
Data Types of c#:
integer - int va -> 4 Bytes ;
Long - long var -> 8 Bytes ;
Double - double var -> 8 Bytes ;
floating - float var -> 4 Bytes;
char var = 'A' -> 2 Bytes;
bool var = true / false -> 1 bit ;
string var = 'Sayan' -> 2 Bytes / Char ;
*/
//Taking Inputs
// string inp = Console.ReadLine();
//Console.WriteLine(inp);
//int a = 34;
//float b = 34.4F; // F at last for float
//double c = 34.4; // no need to add D for double, but add D for less ambiguity wrt float
//bool isgreat = true;
//char d = 'D'; // in SINGLE quotes
//string e = "This is a string";// in Double quotes
// //Console.WriteLine (a);
// //Console.WriteLine (b);
// //Console.WriteLine (c);
// //Console.WriteLine(isgreat);
// //Console.WriteLine(d);
// // Console.WriteLine(e);
/////////////////////////// Type Casting //////////////////////////////////////////
////There are two types of Typecasting
////1 . Implicit -------> char to int to long to float to double
//int x = 3; //x is int, so it can be promoted to all its right side data types
//double y = x; //no error
//char z = 'A';
//y = z; // no error
////int z = y; // error
////2 . Explicit --> int x = (int) 3.5 ;
//double x1 = (double)3.5;
///3. Built in methods
//int x = 3;
//double y = 4;
//float z = 'y';
//float varr = Convert.ToInt32(3.55); //Convert.ToInt64 ;
////Convert.ToDouble;
////Convert.ToString;
//string sx = "34 is amazing ";
//Console.WriteLine(x);
//Console.WriteLine(y);
//Console.WriteLine(z);
/*Console.WriteLine("hello world");
Console.WriteLine("hello sayan");
Console.Write("Hellooo");
Console.WriteLine(" hello sayan and number " + har);*/
//Console.WriteLine("Whats yr name : ");
//string name = Console.ReadLine();
//Console.WriteLine("Hey " + name);
//Console.WriteLine("Candies you want : ");
//string candies = Console.ReadLine();
////Console.WriteLine("you will get " + candies +4 ); // we want candies +4 here
////Console.WriteLine("you will get " + Convert.ToInt32(Convert.ToInt32(candies) + 4) ); // we are converting int to int, waste resources
//Console.WriteLine("you will get " + (Convert.ToInt32(candies) + 4)); // optimized
// Operators
/*
1. Arithmatic
Console.WriteLine("The value of a + b is " + (a + b));
Console.WriteLine("The value of a - b is " + (a - b));
Console.WriteLine("The value of a * b is " + (a * b));
Console.WriteLine("The value of a / b is " + (a / b));
2. Assignment --> = += -= *= /=
3. Logical --> && || ! ^ // 0 is false, all other nos are true
4. Comparison --> == > < >= <= !=
*/
//int a = Math.Max(34, 345);
//Console.WriteLine(a);
//double b = Math.Sqrt(35);
//Console.WriteLine(b);
//string hello = "Hello world \" hello "; // \" -> " ; \n -> new line ; \t -> tab space
//Console.WriteLine(hello.Length);
//Console.WriteLine(hello.ToUpper());
//Console.WriteLine(hello.ToLower());
//String interpolation:
//string name = Console.ReadLine();
//string candies = Console.ReadLine();
//Console.WriteLine($"Your name is {name}. You will get {} candies "); //like in python
//Console.WriteLine(hello.IndexOf("ld"));
// Console.WriteLine(hello.Substring(3)); //index : start = 3, end = end;
//Console.WriteLine(hello);
Console.ReadLine();//last line always
// Console.WriteLine(" hello sayan"); // will not be printed
/*
* . This is a
* . multiline comment
*/
}
}
}
Comments
Post a Comment