Tuesday, 12 March 2013

Delegates in C#

It is also an user defined type which is used for invoking or calling the methods of a class.

A method that is defined under a class can be called in 2 different ways
  • With the help of object of a class if it is non static or name of a class if it is static.
  • By using the delegate also we can call  the method of a class even if it is static or non static.
Note: Calling the method in the 1st process is different than calling the method in the 2nd process.

Calling a method using a Delegate

       If we want to call a method using a delegate we need to adopt the following process
  • Defining a delegate:   
[<modifiers>] delegate <void/type> <Name> ([<Parameter Definition's>])

The definition of a delegate is similar to a method definition where a method will have body whereas a delegate will not have any body where we use these delegates for calling these methods.

Note: While defining a delegate make sure the I/O parameters of Delegates are same as the I/O parameters of the method we want to call with the help of a delegate.
  • As the delegate is a type, after defining a delegate to consume it we need to create an object of it and while creating the object, the method we want to call using the delegate should be passed as a parameter to the delegates constructor.
  • Now call the delegate by passing the required parameter value so that the method gets executed internally.

Delegate Example


using System;
namespace CSharpConsole
{
    class DelDemo
    {
        public void Add(int x, int y)
        {
            Console.WriteLine(x + y);
        }
        public static string SayHello(string name)
        {
            return "Hello " + name;
        }
        public delegate void AddDel(int a, int b);
        public delegate string SayDel(string name);

        static void Main()
        {
            DelDemo obj = new DelDemo();
            AddDel ad = new AddDel(obj.Add);
            SayDel  sd = new SayDel (DelDemo.SayHello);
            ad(100, 50); ad(234, 434); ad(672, 157);
            Console.WriteLine(sd("AAA"));
            Console.WriteLine(sd("BBB"));
            Console.WriteLine(sd("CCC"));
            Console.ReadLine();
                   
        }
    }
}

Monday, 11 March 2013

Indexers in Csharp

These are also use for providing access to the values of the class outside of the class outside of the class like a property but provides access to a value with the specific name but indexers provides access to the value with the object of a class using index positions just like an array.
We define indexers in a class as following:

 Syntax:
[<modifiers>]<type> this [int index or srting name]
{
[get{<statements>}]
[set{<statements>}] 
}

Indexers are defined very much similar to properties but an indexer doesn't have any name. In the place of name we use the 'this' keyword which means we are definning an indexer object of that class starts providing access to the values that are present inside the class, either with the help  of index or name.

Add a class Employee.cs and write the following code:

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

namespace CSharpConsole
{
    class Employee
    {
        int _Empno;
        string _Ename, _Job;
        double _Salary;
        public Employee(int Empno)
        {
            this._Empno = Empno;
            this._Ename = "Leena";
            this._Job = "Developer";
            this._Salary = 5000;
        }
        public object this[int index] // accessing by 'index' 
        {  
            //read/wrtie properties with conditions
            get
            {
                if (index == 0)
                    return _Empno;
                else if (index == 1)
                    return _Ename;
                else if (index == 2)
                    return _Job;
                else if (_Salary == 3)
                    return _Salary;
                return null;
            }
            //read/write properties with conditions
            set
            {
                if (index == 1)
                    _Ename = value.ToString();
                else if (index == 2)
                    _Job = value.ToString();
                else if(index==3)
                    _Salary =(Convert.ToDouble(value));
            }
        }
        public object this[string name]   //accessing by'name'
        {
            get
            {
                if (name == "Empno")
                    return _Empno;
                else if (name == "Ename")
                    return _Ename;
                else if (name == "Job")
                    return _Job;
                else if (name == "Salary")
                    return _Salary;
                return null;
            }
            set
            {
                if (name == "Ename")
                    _Ename = value.ToString();
                else if (name == "Job")
                    _Job = value.ToString();
                else if (name == "Salary")
                    _Salary = Convert.ToDouble(value);

            }
        }
    }
}
Add another class TestEmployee.cs and write the following code:
using System;

namespace CSharpConsole
{
    class TestEmployee
    {
        static void Main()
        {
            Employee emp = new Employee(1001);
            Console.WriteLine(emp[0]);
            Console .WriteLine (emp [1]);
            Console.WriteLine(emp[2]);
            Console.WriteLine(emp[3]);
            
            // Assigning a new value
            emp[1] = "Cheryl";
            emp["Ename"] = "BA";
            emp[3] = 8000;

            Console.WriteLine(emp["Empno"]);
            Console.WriteLine(emp["Ename"]);
            Console.WriteLine(emp["Job"]);
            Console.WriteLine(emp["Salary"]);
            Console.ReadLine();
        }
    }
}

First outing in Hyderabad with friends!!

     Finally, for the 1st time in 2 months we roamed in Hyderabad. I, along with my room mates went to NTR garden on Saturday. Actually we had planned to go to Lumbini Garden but unfortunately it was closed because of the trouble going on in Hyderabad. So then we finally went to NTR, We went around 3 in the afternoon and returned around 8 at night. We thoroughly enjoyed ourselves.
     Now back to the task which sudeep gave us. Sudeep had told me to do some updations such as some validations, to be able to edit, delete and add new courses at runtime etc. I am still working on it and I hope to finish it as soon s possible.

Friday, 8 March 2013

Women's Day Special

Today, on Women's Day I got a bunch of Beautiful flower, Chocolate and a Sweet Gift from Inforica. It was a Good Surprise for me when I reached office and saw a bunch of flower, chocolate and a gift already kept on my desk, Thank you so much Sudeep for making every Women feel special today, in Inforica.

Today, I Solved some online Sample papers of IBPS Exam just for practice since I  have applied for that Examination and the exam day is coming closer. Apart from this I am doing the Updations that Sudeep told me to do in my GetJob Project. I am done with adding Master page and linking it with the Content pages so that the Title and Menu Control will appear in each page. Now left with some validation part. Will probably complete today.

Normailization in SQL Server

Normalization is a process of minimizing data redundancy with a series of steps called as normal forms.

The total normalization process includes the following normal forms.
  • First Normal Form (1NF)
  • Second Normal Form (2NF)
  • Third Normal Form (3NF)
  • Boyce Codded Normal Form (BCNF)
  • Fourth Normal Form (4NF)
  • Fifth Normal Form (5NF)
  • Restrict Union Normal Form (RUNF)
  • Project Join Normal Form (PJNF)
  • Sixth Normal Form (6NF)
First Normal Form (1NF):  A table is said to be in 1NF if and only if a primary key is defined for that table and the table does not contain any multivalued columns.

Second Normal Form (2NF): A table is said to be in 2NF if and only if the table is in 1NF and no partial dependencies exist in the table.

Third Normal Form (3NF): A table is said to be in 3NF if and only if the table is in 2NF and no transient dependencies exist in the table.



Thursday, 7 March 2013

Properties

There are also members of a class using which we can provide access to the value of a class outside of the class.
If at all a class is associated with any values and if we want those values to be accessible outside of the class we can provide access to those values in two different ways.
  • By storing value under a public variable we can provide access to that value outside the class but in this case the public variable gives get value or set the value.
       public class Test
       {
       public int x=100;
       }
       Test obj=new Test()
       int a=obj x
       obj.x=100
  • By storing the value under a private value also of a class by defining a property on that variable given in three different ways
  1. Both get and set access(Read/write/property)
  2. Only get access(Read only property)
  3. Only set access(write only property)
Syntax to define a property:

      [<modifiers>]<type>[Names]
      {
      [get{statements}]  // Get accessor
      [set{statements}]  // Set accessor
      }