Apuntes
C Sharp basic info
Contenido del apunte (1)
Página 1
Constructor:
when we try to instantiate class using new keyword first it will call constructor and after that it will allocate memory for object in heap.
Static Constructor:
used to initialize static data or perform particular action required only once. This is automatically called on first instantiation or first time calling/ accessing static members.(Static members are referranced).
Calling base class constructor in derived class constructor:
Using : base(..) -> we can call.
Ex:
public class BaseClass
{
int num;
public BaseClass()
{
Console.WriteLine("in BaseClass()");
}
public BaseClass(int i)
{
num = i;
Console.WriteLine("in BaseClass(int i)");
}
public int GetNum()
{
return num;
}
}
public class DerivedClass : BaseClass
{
// This constructor will call BaseClass.BaseClass()
public DerivedClass() : base()
{
}
// This constructor will call BaseClass.BaseClass(int i)
public DerivedClass(int i) : base(i)
{
}
static void Main()
{
DerivedClass md = new DerivedClass();
DerivedClass md1 = new DerivedClass(1);
}
}
/*
Output:
in BaseClass()
in BaseClass(int i)
*/
Early Binding and late Binding
Polymorphism
Polymorphism means many forms (ability to take more than one form). In Polymorphism poly means “multiple” and morph means “forms” so polymorphism means many forms
- Compile Time Polymorphism (Called as Early Binding or Overloading or static binding)
- Run Time Polymorphism (Called as Late Binding or Overriding or dynamic binding)
Interface:
https://dzone.com/articles/c-interfaces-what-are-they-and
when we go for interface and abstract class in c#
http://www.c-sharpcorner.com/article/when-to-use-abstract-class-and-interface-in-real-time-projects/
Join 2 datatables using Linq
var res= from table1 in datatable1.AsEnumerable()
join table2 in datatable2.AsEnumerable() on table1.Field<string>("ID") equals table2.Field<string>("ID") into jf
from r in jf.DefaultIfEmpty
select new{
ID= table1.Field<string>("ID") ,
Name= table1.Field<string>("name"),
Stock = r==null?0 : r.Field<int>("Stock")
}
Session Object
https://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net
Información
- Descripción
- Apunte sobre C Sharp basic info, creado por Sai Krishna el 19/12/2017.
- Creado por
- Sai Krishna
- Visitas
- 0
- Valoración