C# Basics ii
/////////////// player.cs ///////////////////
using System;
using System.Collections.Generic;
using System.Text;
namespace beginner_2
{
class Player
{
public string name = "sayan";
private int health = 49;
public int gethealth()
{
return health;
}
public void sethealth(int h)
{
health = h;
}
}
}
/////////////// main.cs ///////////////////////
using System;
namespace beginner_2
{
class Program
{
const int a = 9; // Global var
static void Greet() // Greet belongs to the class Program , not returning value
{
Console.WriteLine("Good morning");
}
static float avg(int a , int b, int c)
{
float d = (a + b + c) ;
return d/3;
}
static void Main(string[] args) //Method == Function
{
//Conditional
//int age = 16;
//string agestr = Console.ReadLine();
//int age = Convert.ToInt32(Console.ReadLine()); // like python
//bool isban = true;
//if (age >= 18 && isban == false)
//{
// Console.WriteLine("You can drive");
//}
//else if (age >= 18 && isban == true)
//{
// Console.WriteLine("You cant drive");
//}
//else
//{
// Console.WriteLine("You cant drive");
//}
//int age = 20;
//switch (age)
//{
// case 18:
// Console.WriteLine("wait for an year");
// break;
// case 20:
// Console.WriteLine("You are 20");
// break;
// default:
// Console.WriteLine("Enjoy !");
// break;
//}
// Loops //
//int i = 0;
//while (i < 10) //0 to 9
//{
// Console.WriteLine(i);
// i++;
//}
//do
//{
// Console.WriteLine(i);
// i++;
//} while (i < 10);
//for (int i=0; i < 5; i++) // for (initializer , Conditon for next iteration , value of var in next iteration ) {Operation};
//{
// Console.WriteLine(i);
//}
//Greet();
//Console.WriteLine(avg(2,2,3));
//Console.WriteLine(a);
// OOPs - Classes and Obects
Player tommy = new Player();
Console.WriteLine(tommy.gethealth());
tommy.sethealth(89);
Console.WriteLine(tommy.gethealth());
Console.ReadLine(); // used for the complier results to not dissapear
}
}
}
Comments
Post a Comment