Friday, 1 July 2011

What is Constraints ?

Constraint is a mechanism/Property it is used to prevent the invalid data entry in to the table is called constraint. These constraints ensure the accuracy and reliability of the data into the tables.
Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).

Difference between Function and StoreProcedure ?

1. functions MUST return a value, procedures need not be.
2. sp takes input,output parameters, function takes only input parameters.
3. sp can not be called directly into DML statements , but functions can be called directly into DML statements.
4. Procedure can return zero or n values whereas function can return one value which is mandatory.
5. Functions can be called from procedure whereas procedures cannot be called from function.
6. Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
7. We can go for transaction management in procedure whereas we can't go in function.
8. Function can be used inside the queries but Store procedure never used inside the queries For Example
      Given below:
      select avg(salary) from employee;// allowed here
      avg(): is function
      Select sp(salary) from employee // Not allowed here
      sp(): is stored Procedure
9. Print function can not be called within the function but it can be called within the stored procedure.
10. A stored procedure can return multiple parameters but a function can return only one value.

String.Empty Vs Empty Quotes ?


The difference between string.Empty and "" is very small. String.empty will not create any object while "" will create a new object in the memory for the checking. Hence string.empty is better in memory management.
But do not forget to make a checking for null value if you are also expecting null value in the comparison.

What's the difference between Response.Write() and Response.Output.Write()?


Response.write() is used to display the normal text and Response.output.write() is used to display the formated text.
Response.write - it writes the text stream.
Response.Write("<h1>"+  DateTime.Now.Tostring() + "</h1>");
 
Response.output.write - it writes the HTTP Output Stream. 
Response.Output.Write("<h2>Process running as {0}</h2>",WindowsIdentity.GetCurrent().Name);
As per ASP.NET 3.5, Response.Write has 4 overloads, while Response.Output.Write has 17 overloads.

What is the Static Member ?


When you declare a member variable as static and when the application starts, the compiler creates a copy of that member. This member would be maintained by the compiler while the program is running. If you declare an instance of a class, the static member is not part of the object: the compiler creates and maintains the static member, whether you use it or not, whether you declare a class variable or not.
When a class has a static member variable, you don't need to declare an instance of that class to access the static member variable. When the application starts, the member variable is automatically available and you can access it when necessary. You can access it either to retrieve its value or to modify it.
Variables and methods marked static belong to the class rather than to any particular instance of the class. These can be used without having any instances of that class at all. Only the class is sufficient to invoke a static method or access a static variable. A static variable is shared by all the instances of that class i.e only one copy of the static variable is maintained.

What is the Static Class ?


We can declare a static class. We use static class when there is no data or behavior in the class that depends on object identity. A static class can have only static members. We cannot create instances of a static class using the new keyword. .NET Framework common language runtime (CLR) loads Static classes automatically when the program or namespace containing the class is loaded.

Here are some more features of static class
  • Static classes only contain static members.
  • Static class cannot create any objects
  • Static classes are sealed.  
  • Static class can have only private constructors 
  • Static loads automatically when the CLR loads the namespace of the class.

What is difference between class and structure ?

1. Classes are reference types and structs are value types.
2. A class variable can be assigned null because classes are reference type. But we cannot assign null to a struct variable because structs are value type.
3. When you instantiate a class, it will be allocated on the heap. When you instantiate a struct, it gets created on the stack.
4. Classes support inheritance. But there is no inheritance for structs.
5. Classes are used for complex and large set data. structs are simple to use.
6. Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.
7. Classes can have explicit parameter less constructors. But structs cannot have this.
8. Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.
9. By default, all of the members of a class are private and, by default, all of the members of a structure are public.
10.  There is no data hiding features comes with structures. Classes do, private, protected and public.
11.  A structure can't be abstract, a class can.
12.  A structure is contain only data member , but class contain data member and member function.
13.  Struct cannot have default constructor but class have default constructor. 
14.  Structs can't have destructors, but classes can have destructors.
   
Note : a struct is a value type, a class is a reference type.  Value types hold their value in memory where they are declared, but reference types hold a reference to an object in memory. If you copy a struct, C# creates a new copy of the object and assigns the copy of the object to a separate struct instance. However, if you copy a class, C# creates a new copy of the reference to the object and assigns the copy of the reference to the separate class instance.