| Hello_world |
| using System; //compile csc test2.cs class test2 { public static void Main() { Console.WriteLine("Hello World"); } } |
![]() |
Know C# Now: and it is very simple and easy.
|
![]() |
Code:
|
![]() |
public class
test |
|
using System;
//compile csc class_object.cs
public class explain_class
{
public string str = "string variable in class";
public int n = 123456;
public explain_class() { Console.WriteLine("constructor Evoked ");}
~explain_class() { Console.WriteLine("destructor Evoked ");}
public void write()
{
Console.WriteLine(str);
}
}
class test2
{
public static void Main()
{
Console.WriteLine("Hello World");
// creating an instance and objects
explain_class ec1 = new explain_class();
//object ec is created with new key word.
// when you write explain_class ec;
//an object is created without a refenece
// referencing object to object is allowed
explain_class ec2 = ec1;
//here ec1 and ec2 refer to the same object reference
///
//access a string variable with an object created from explain_class
Console.WriteLine("Acessing an sring variable :" + ec1.str);
// access a non static variable
Console.WriteLine("Acessing an Integer variable : " + ec1.n);
// access method using objects
ec1.write();
ec2.write();
}
} |
![]() |