-------------------------------------------------------------------------------------------------------------------------
namespace FirstConsoleApp
{
public class Program
{
public static void Main()
{
//Declaring Variables
int X = 200; //Constant declare with constant datatype
var inputvar = 123.0; //Constant declare with (var)variable data type
Console.WriteLine("Enter Your value 1"); //Getting 1st value from user
var Input1 = Console.ReadLine();
Console.WriteLine("Enter Your Value 2"); //Getting 2st value from user
var Input2 = Console.ReadLine();
var Output1 = Input1 + Input2;
Console.WriteLine("Your answer is:" + Output1); //Writing User Output
// Conditional Statements Overview of usage
// IF ELSE
Console.WriteLine("Enter Your Value for if condition"); //Variable getting from user:
var User_Input = Convert.ToInt32(Console.ReadLine()); //Converting user input to Int32 format
if (User_Input == 1) //if condition initialization
Console.WriteLine("Your Input:1 if Pass");
else if (User_Input==2) //else if condition initialization
Console.WriteLine("Your input:2 else if Pass");
else //else condition initialization
Console.WriteLine("Your input:Others else pass");
//Switch Case Statement
Console.WriteLine("Enter Your Value for switch case processing");
var User_InputSwitch= Convert.ToInt32(Console.ReadLine()); //Variable getting from user:
switch (User_InputSwitch) //switch case initialization
{
case 0: //Case0
{
Console.WriteLine("Your input:0 Case0 Pass");
break;
}
case 1: //Case1
{
Console.WriteLine("Your input:0 Case0 Pass");
break;
}
case 2: //Case2
{
Console.WriteLine("Your input:2 Case2 Pass");
break;
}
case 20: //Case20
{
Console.WriteLine("Your input:20 Case20 Pass");
break;
}
default: //Case20
{
Console.WriteLine("Your input:Undefined as per case");
break;
}
}
//Loops //For Loop initialization
for (int Production = 0; Production < 21; Production++)
{
if (Production == 5) { continue; } //Skipping perticular execution cycle
Console.WriteLine(Production);
Console.WriteLine("Good Going");
if (Production == 10) { break;} //Breaking the loop after 5 running cycles
}
//While Loop initialization
int WhileLoop = 0; //While Loop control Variable Initialization
while (WhileLoop < 21) //While Loop Condition initialization
{
Console.WriteLine("While Loop Running Count"+WhileLoop); //Loop Statement
WhileLoop = WhileLoop + 1; //Loop Control Variable Increment
if (WhileLoop == 10) { break; } //Breaking the loop after 5 running cycles
}
}
}
}
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
//Array declaration
namespace FirstConsoleApp //Application Name
{
public class Program
{
public static void Main()
{
int arval = 30;
int[] Data_Mem =new int[10]; //Array declare Var=Data_Mem
Data_Mem[0] = 10;
Data_Mem[1] = 11;
Data_Mem[2] = 12;
Data_Mem[3] = 13;
Data_Mem[9] = 16;
}
}
}
----------------------------------------------------------------------------------------------------------------------------
namespace FirstConsoleApp //Application Name
{
public class Program
{
/*Main-Method**********************************************************************/
public static void Main()
{
Console.WriteLine("I am main Method"); //Executing code from Main-Method
display(); //Calling without argument method "display"
add(10, 20); //Calling with argument without return method "add"
var add_result = addition(1, 2, 3); //Calling with argument with return method "addition"
Console.WriteLine("added result:" + add_result);
}
/****************************************************************************************/
/*Method-display**********************************************************************/
public static void display()
{
Console.WriteLine("I am method display");
}
/*****************************************************************************************/
/*Method-add******************************************************************************/
public static void add(int val1, int val2)
{
Console.WriteLine("Addition Value:"+(val1+val2));
}
/*****************************************************************************************/
/*Method-addition******************************************************************************/
/* While declaring method instead of void int (the data type will vary based on retun value type) used */
public static int addition(int val1, int val2, int val3)
{
return (val1 + val2 + val3);
}
/*****************************************************************************************/
}
}
0 Comments