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.
  • Built in namespaces like system. When you are referring you need to use a key word like using.
    • e.g.. using System;
      using System.Collections.Generic;
      using System.Text;
  • Start of your custom namespace

     {

    • Your class starts e.g. class do_something
      • {

        method or function starts

        {

        }

        method ends

      • }
    • Your class do_something
    • A class that stands as an Entry point

      public static void Main()

      {

                      your code that will retrieve output /work done by the other classes

      }

    }

  •  End of your custom namespace
Code:

using System;
using System.Collections.Generic;
using System.Text;
//start with custom namespace
namespace string_maipulation
{
class stringhandler
{
public void joinarry()
{
Console.WriteLine("hello");
}
}
class Program
{
static void Main(string[] args)
{
stringhandler ss = new stringhandler();
ss.joinarry();
Console.ReadLine();

}
}
}//end of the namespace

 
 
  • Declaration: A class is declared with a key word "class". The accessor "public" or private or protected should be the first one to begin with

public class test
{
    //Fields, properties, methods and events go here...
 // these are class members

}
 

  • Instantiation:
    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();
}
}