Friday, February 14, 2020

Data base Optimization


Database is the most important and powerful part of any application. If your database is not working properly and taking long time to compute the result, this means something is going wrong in database.

  1. ·         Use  index on table
  2. ·         Use  to Avoid Null value in fixed length field
  3. ·         Use  Appropriate Datatype
  4. ·         Use  Common Table Expressions (CTEs) instead of Temp table
  5. ·         Use  Appropriate Naming Convention
  6. ·         Use  UNION ALL instead of UNION
  7. ·         Use  Small data type for Index 
  8. Use  the stored procedure because stored procedures are fast and easy to maintain for 



     

Abstract Class

I  have implemented most of my projects abstract class as a base class and all derived classes must implement abstract definition. we can avoid duplicate code.
·         creating something that provides common functionality to unrelated classes, use an interface
·         Abstract classes allow to provide default functionality for the subclasses.
·         creating something for objects that are closely related in a hierarchy, use an abstract class
If the base class will be changing often and an interface was used instead of an abstract class, we are going to run into problems. Once an interface is changed, any class that implements that will be broken. Now if it’s just you working on the project, that’s no big deal. However, once your interface is published to the client, that interface needs to be locked down. At that point, you will be breaking the clients code.


abstract class TestClass {
 
    protected int myNumber;  
    public abstract int numbers
    {
        get;
        set;
    }
}
 
class absDerived : TestClass {
 
    public override int numbers
    {
        get
        {
            return myNumber;
        }
        set
        {
            myNumber = value;
        }
    }
}
 
class order{
 
    // Main Method
    public static void Main)
    {
        TestDerived d = new TestDerived();
        d.numbers = 7;
        Console.WriteLine(d.numbers);
    }
}

c# generics


generics to write a class or method that can work with any data type. When the compiler encounters a constructor for the class or a function call for the method, it generates code to handle the specific data type.
It helps you to maximize code reuse, type safety, and performance

·         Use generic types to maximize code reuse, type safety, and performance.
·         The most common use of generics is to create collection classes.

public class GenericList
{
    public void Add(T input) { }
}
class TestGenericList
{
    private class ExampleClass { }
    static void Main()
    {
        // Declare a list of type int.
        GenericList list1 = new GenericList();
        list1.Add(1);

        // Declare a list of type string.
        GenericList list2 = new GenericList();
        list2.Add("");

        // Declare a list of type ExampleClass.
        GenericList list3 = new GenericList();
        list3.Add(new ExampleClass());
    }
}

c# Memory Clean of Objects


finally statement is to ensure that the necessary cleanup of objects, usually objects that are holding external resources, occurs immediately, even if an exception is thrown. One example of such cleanup is calling Close on a FileStream immediately after use instead of waiting for the object to be garbage collected by the common language runtime, as follows

static void CodeobjectCleanup()
{
    System.IO.FileStream file = null;
    System.IO.FileInfo fileInfo = new System.IO.FileInfo("C:\\file.txt");

    file = fileInfo.OpenWrite();
    file.WriteByte(0xF);

    file.Close();
}