Tuesday, 12 March 2013

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
      }


Wednesday, 6 March 2013

Methods of a 'class' in CSharp

A class is a collection of members, where members of class can be off various kinds like :
  • Fields
  • Members
  • Constructors
  • Destructors
  • Properties
  • Indexes
  • Events
  • Delegates
  • Enum
Destructor: This is also a special method present under a child class same like a constructor but constructor method gets called when object of class is created and destructor is called whenobject of class is destroyed.
   Both constructor and destructor method will exactly have the same name i.e the name of the class which they have. To differentiate between this two we use 'tidle' operation before the destructor method.

class Test
 {
    Test() 
     {
        //Constructors
     } 
   ~Test()
    {
      //Destructors
    }
}
  • Destructor methods cannot be applied with any modifirs or parameters.
  • Garbage Collector is responsible for destroying the object of class and when the object of class is being destroyed, destructor methods gets called and moreover Garbage Collector can destroy the object of class in any of the following three classes.
  1. In the end of a program's execution each and every object i.e associated with the program is automatically destroyed.
  2. Sometime in the middle of a programs execution implicit calling of Garbage Collector takes place provided the memory is full that it identifies finds unused object and destroys them.