Friday, 22 February 2013

Polymorphism

Its an approach of definning different methods with a different behaviour i.e whenever the input changes the output or behaviour also changes accordingly which can be implemented under a language using different approaches like Overloading, Overriding and Hiding.

Overloading
This is again of three types:
  • Method Overloading
  • Constructor Overloadding
  • Operator Overloading 
Method Overloading: It is an approach of definnig multiple methods under a class with the same name, by changing the signature of those methods. Changing the signature of those method in the sense we can change the number of parameters being passed to the method or order of parameters being passed to method.

//Method overloading

using System;

namespace CSharpConsole
{
    class LoadDemo
    {
        public void Show()
        {
            Console.WriteLine(1);
        }
        public void Show( int x)
        {
            Console.WriteLine(2);
        }
        public void Show(string s)
        {
            Console.WriteLine(3);
        }
        public void Show(int x, string s)
        {
            Console.WriteLine(4);
        }
        public void Show(string s, int x)
        {
            Console.WriteLine(5);
        }

        static  void Main()
        {
            LoadDemo d = new LoadDemo();
            d.Show();
            d.Show(10);
            d.Show("hello");
            d.Show(5,"leena");
            d.Show("bansiwal", 15);
            Console.ReadLine();
        }
    }
}

Thursday, 21 February 2013

Axure Tooltip

         Today, Sudeep showed us how to use a tool called 'Axure'. It is a very powerful wire-framing tool, that lets you create clickable wire-frames very quickly. The Business Analyst acts as a middle-ware between the Software developer and the Client. When a Client places an requests the BA analyses those requests and proceeds the work accordingly.
         We also created 2-3 pages using this tool  under the guidance of Sudeep and it was nice to learn something new.

Extension Methods in CSharp

This is a new feature that has been inter choose in C#.Net 3.0 that allows us to add new methods into an existing class without editing the source code of the class.

Defining Extension:
  •  Extension methods must be defined under static class only so every extension method is static by default but once the method is bound with another class it gets converted into non static and it can be called by using old classes object.
  • The first parameter of an extension method  is to specify to which class the method has to be bound with and we call it as a binding parameter which should be defined as following. 
         this<class name><obj>
  • If required we can also pass normal parameters to an extension method which should start from the second place of parameter list and all this parameter will be considered while calling the method.
  • If an extension method is defined with n parameters while calling the methods we will be having n-1 parameters only because binding parameters is excluded.
Add a class oldclass.cs and code the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpConsole
{
 class oldclass
 {
  public int a;
  public oldclass (int a)
  {
   this.a=a;
  }
   public void show1()
  {
   Console.WriteLine("Method One:  " + this.a);
  }
   public void show2()
  {
   Console.WriteLine("Method Two:  " + this.a);
  }
 }
}
// Now add a newclass.cs and code the following
using System;
namespace CSharpConsole
{
  static  class newclass
 {
  public static void show3(this oldclass obj)
   {
    Console.WriteLine("Method three ");
   }
    public static void show4(this oldclass obj, int x)
   {
    Console.WriteLine("Method four: "  + x);
   }
    public static void show5(this oldclass obj)
   {
    Console.WriteLine("Method five: " + obj.a);
   }
 }
}
// Again add a new classTestold.cs to test the above code

using System;

namespace CSharpConsole
{
 class Testold
 {
   static void Main()
   {
    oldclass obj = new oldclass(10);
    obj.show1();
    obj.show2();
            
    // Calling Extension Methods
     obj.show3();
     obj.show4(50); obj.show5();
     Console.ReadLine();
   }
 }
}

Tuesday, 19 February 2013

     Today we practiced the concept of Inheritance, Some SQL queries based on joins, indexes, set operators etc. We also learnt the concept of security in SQL Server, and that how certain permissions or privileges can be granted to other users by the users who own the database etc...
     It was a good day... Learning more and more every day and more important enjoying while learning.

Monday, 18 February 2013

Inheritance in CSharp

Children inheriting the property of there parents is known as inheritance which gives reusability we can implement the same rule in our object oriented languages and established parent child relationship between classes so that parent class members can be consumed by child classes i.e child classes are reusing the parent class members without rewriting them again.

A parent class can have any number of child classes and members of parent class can be consumed under all the child classes.

Private members of a class cannot be inherited and acquired by the child classes.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpConsole
{
    class Class1
    {
        public Class1()
        {
            Console.WriteLine("Class1 constructor called");
        }
        public void test1()
        {
            Console.WriteLine("First Method");
        }
        public void test2()
        {
            Console.WriteLine("Second Method");
        }

    }
}// Now add another class Class2.cs and write the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpConsole
{
    class Class2:Class1
    {
        public Class2()
        {
            Console.WriteLine("Class2 constructor called");
        }
        public void Test3()
        {
            Console.WriteLine("Third method called");
        }

        static void Main()
        {
            Class2 c = new Class2();
            c.test1(); c.test2(); c.Test3();
            Console.ReadLine();
         }
    }
}


Each day learning something New and Interesting

Today, we spent more time upon writing SOL queries. Created Sub queries under that I did :
  • Single Row Sub Queries.
  • Multi-Row Sub Querries.
  • Nested Sub querries And
  • Co-related sub queries. I also created Indexes . Indexes is a relational database are mainly use to make the data retrival faster similiar to index available at the end of the book. There are two types of Indexes:
  • Clustered Index : Cluster index is the index that will arrange the rows physically in the memory in sorted order.
  • Non-Clustered Index : Cluster index is the index that will not arrange the rows physically in the memory in sorted order.
So I created the Index by name DnoIdx on Emp table that I created before and tried both clustered/non clustered creation of Indexes.
In the secod half I tried to analyze and learn C# basics like:
  • Static Methods vs Non Static Methods
  • Static Constructors vs Non Static Constructors
  • Static Classes
It has become the everyday Routine to learn Something new related to SQL Server and C#.Net and implement it practically.Looking forward for more such new topics everyday, so that I can at the end, able to know almost everything about the .Net language concepts(C# and ASP),AJAX and SQL Server far better.

 

Static Constructor Vs Non-Static Constructor

  • A Constructor that is defined using static keyword is a static constructor. Rest of the others are Non-Static only. 
  • Static Constructor is the first block of code which executes under a class where as Non-Static Constructor gets executed only after creating the object of class as well as each and every time the object of class is created.
  • In the life cycle of a class a Static Constructor gets called one and only one time whereas a Non-Static Constructor gets called either for zero(no objects are created) or n times (n objects are created).
  • A Static Constructor can never be parametrized because it is the first block of code that executes in a class and more over it is implicitly called and Non-Static constructors can be parametrized because they are explicitly called and we have a chance of sending values to the parameters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApps
{
    class StatCon
    {
        static StatCon()
        {
            Console.WriteLine("Static Constructor Called");
        }
        public StatCon()
        {
            Console.WriteLine("Non-Static Constructor Called");
        }
        static void Main()
        {
            Console.WriteLine("Main Method Called");
            StatCon s1 = new StatCon();
            StatCon s2 = new StatCon();
            StatCon s3 = new StatCon();
            Console.ReadLine();
        }
    }
}