Last active
August 2, 2021 09:39
-
-
Save rapando/861881cc460b061b76f26a68e71e0f14 to your computer and use it in GitHub Desktop.
C# Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
struct Person | |
{ | |
private string _name; | |
private int _age; | |
public static int st; | |
public void SetValues(string name, int age) | |
{ | |
_name = name; | |
_age = age; | |
} | |
public void PrintValues() | |
{ | |
Console.WriteLine($"Name : {_name}, Age : {_age}"); | |
} | |
} | |
enum Days | |
{ | |
Sun, | |
Mon, | |
Tue, | |
Wed, | |
Thu, | |
Fri, | |
Sat | |
}; | |
namespace HelloWorld | |
{ | |
class Rectangle | |
{ | |
private double _length; | |
private double _width; | |
private static int _st; | |
public Rectangle() | |
{ | |
Console.WriteLine("The object is being created"); | |
} | |
public Rectangle(int a) | |
{ | |
Console.WriteLine($"The object is being created with a default value : {a}"); | |
} | |
~Rectangle() | |
{ | |
_length = 0.0; | |
_width = 0.0; | |
Console.WriteLine("Destructor is running"); | |
} | |
public void StaticIncrementer() | |
{ | |
_st++; | |
} | |
public void PrintStaticVar() | |
{ | |
Console.WriteLine($"St : {_st}"); | |
} | |
public void SetLength() | |
{ | |
Console.Write("Enter Length : "); | |
_length = Convert.ToDouble(Console.ReadLine()); | |
} | |
public void SetWidth() | |
{ | |
Console.Write("Enter Width : "); | |
_width = Convert.ToDouble(Console.ReadLine()); | |
} | |
public double GetArea() | |
{ | |
return _length * _width; | |
} | |
} | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var rectangle = new Rectangle(); | |
var rectangleTwo = new Rectangle(45); | |
rectangle.SetLength(); | |
rectangle.SetWidth(); | |
var area = rectangle.GetArea(); | |
Console.WriteLine($"Hello World, the area of the rectangle is {area}"); | |
var waiting = new DateTime(2021, 10, 10, 17, 58, 1); | |
var chat = $"Message sent at {waiting:t} on {waiting:D}"; | |
Console.WriteLine(chat); | |
var sam = new Person(); | |
sam.SetValues("Samson", 25); | |
sam.PrintValues(); | |
// -- Enums | |
var WeekdayStart = (int) Days.Mon; | |
var WeekdayEnd = (int) Days.Fri; | |
Console.WriteLine($"The work week starts at {WeekdayStart} and ends on {WeekdayEnd}"); | |
// Console.ReadKey(); | |
rectangle.StaticIncrementer(); | |
rectangleTwo.StaticIncrementer(); | |
rectangle.PrintStaticVar(); | |
rectangleTwo.PrintStaticVar(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using firstStep; | |
namespace firstStep | |
{ | |
class FirstStep | |
{ | |
public void func() | |
{ | |
Console.WriteLine("SPace One"); | |
} | |
} | |
} | |
namespace HelloWorld | |
{ | |
class Person | |
{ | |
private string _name; | |
private int _age; | |
public Person(string n, int a) | |
{ | |
_name = n; | |
_age = a; | |
} | |
public void Print() | |
{ | |
Console.WriteLine($"Your name is {_name} and you are {_age} years old"); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World there!"); | |
FirstStep fs = new FirstStep(); | |
fs.func(); | |
var person = new Person("Samson", 34); | |
person.Print(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Shape | |
{ | |
class Shape | |
{ | |
protected int Width; | |
protected int Height; | |
public Shape() | |
{ | |
Console.WriteLine("Initialize Shape"); | |
} | |
~Shape() | |
{ | |
Console.WriteLine("Destruct Shape"); | |
} | |
public void SetWidth(int w) | |
{ | |
Width = w; | |
} | |
public void SetHeight(int h) | |
{ | |
Height = h; | |
} | |
} | |
class Rectangle : Shape | |
{ | |
public Rectangle() | |
{ | |
Console.WriteLine("Initialize Rectangle"); | |
} | |
~Rectangle() | |
{ | |
Console.WriteLine("Destruct Rectangle"); | |
} | |
public int GetArea() | |
{ | |
return Width * Height; | |
} | |
} | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var rectangle = new Rectangle(); | |
rectangle.SetWidth(34); | |
rectangle.SetHeight(45); | |
Console.WriteLine($"The rectangle's area is {rectangle.GetArea()}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment