A Pivot Table can automatically sort, count, and total the data stored in one table or spreadsheet and create a second table displaying the summarized data. The PIVOT operator turns the values of a specified column into column names, effectively rotating a table.In simpler word UNPIVOT table is reverse of PIVOT Table, however it is not exactly true. UNPIVOTING is for sure reverse operation to PIVOTING but if during PIVOTING process data aggregated the UNPIVOT table does not return to original table. (Read more here)ROW_NUMBER() returns a column as an expression that contains the row’s number within the result set. This is only a number used in the context of the result set; if the result changes, the ROW_NUMBER() will change.
- Using CTE improves the readability and enables easy maintenance of complex queries.
- The query can be divided into separate, simple, and logical building blocks, which can be then used to build more complex CTEs until the final result set is generated.
- CTE can be defined in functions, stored procedures, triggers or even views.
- After a CTE is defined, it can be used as a Table or a View and can SELECT, INSERT, UPDATE or DELETE Data.
- Include SET NOCOUNT ON statement.
- Use schema name with object name.
- Do not use the prefix “sp_” in the stored procedure name.
- Use IF EXISTS (SELECT 1) instead of (SELECT *).
- Use the sp_executesql stored procedure instead of the EXECUTE statement.
- Try to avoid using SQL Server cursors whenever possible.
- Keep the Transaction as short as possible.
- Use TRY-Catch for error handling.
- Use Type-Safe SQL Parameters
- Use Parameterized Input with Stored Procedures
- Use the Parameters Collection with Dynamic SQL
- Filtering Input parameters
- Use the escape character in LIKE clause
- Wrapping Parameters with QUOTENAME() and REPLACE()
- Root node: A root node contains node pointers to only one branch node.
- Branch nodes: A branch node contains pointers to leaf nodes or other branch nodes, which can be two or more.
- Leaf nodes: A leaf node contains index items and horizontal pointers to other leaf nodes, which can be many.
- Stored procedure can reduced network traffic and latency, boosting application performance.
- Stored procedure execution plans can be reused; they staying cached in SQL Server’s memory, reducing server overhead.
- Stored procedures help promote code reuse.
- Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients.
- Stored procedures provide better security to your data.
- A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.
- A non clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.
- TRUNCATE:
- TRUNCATE is faster and uses fewer system and transaction log resources than DELETE.
- TRUNCATE removes the data by deallocating the data pages used to store the table's data, and only the page deallocations are recorded in the transaction log.
- TRUNCATE removes all rows from a table, but the table structure, its columns, constraints, indexes and so on, remains. The counter used by an identity for new rows is reset to the seed for the column.
- You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint. Because TRUNCATE TABLE is not logged, it cannot activate a trigger.
- TRUNCATE cannot be rolled back.
- TRUNCATE is DDL Command.
- TRUNCATE Resets identity of the table
- DELETE:
- DELETE removes rows one at a time and records an entry in the transaction log for each deleted row.
- If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.
- DELETE Can be used with or without a WHERE clause
- DELETE Activates Triggers.
- DELETE can be rolled back.
- DELETE is DML Command.
- DELETE does not reset identity of the table.
What are temp tables? What is the difference between global and local temp tables?CREATE TABLE #tempLocal ( nameid int, fname varchar(50), lname varchar(50) )CREATE TABLE ##tempGlobal ( nameid int, fname varchar(50), lname varchar(50) )What is a CTE?WITH ExampleCTE (id, fname, lname)AS(SELECT id, firstname, lastname FROM table)SELECT * FROM ExampleCTEDECLARE @myTable TABLE (AutoID int,myName char(50) )Lets say we have to return a non-null from more than one column, then we can use COALESCE function. Lets say we have to return a non-null from more than one column, then we can use COALESCE function. SELECT COALESCE(hourly_wage, salary, commission) AS 'Total Salary' FROM wagesIn this case, If hourly_wage is not null and other two columns are null then hourly_wage will be returned. If hourly_wage, commission are null and salary is not null then salary will be returned. If commission is non-null and other two columns are null then commission will be returned.In this case, If hourly_wage is not null and other two columns are null then hourly_wage will be returned. If hourly_wage, commission are null and salary is not null then salary will be returned. If commission is non-null and other two columns are null then commission will be returned.If hourly_wage is not null and other two columns are null then hourly_wage will be returned. If hourly_wage, commission are null and salary is not null then salary will be returned. If commission is non-null and other two columns are null then commission will be returned.
What is the use of @@TRANCOUNT in SQL Server?
Atomicity is an all-or-none proposition.Consistency guarantees that a transaction never leaves your database in a half-finished state.Isolation keeps transactions separated from each other until they’re finished.Durability guarantees that the database will keep track of pending changes in such a way that the server can recover from an abnormal termination.Above four rules are very important for any developers dealing with databasesFor an example, if you have three records at position one. Both the functions will place all three records at same position of one but the difference comes is when they rank the next record.
RANK() will rank the next record as fourth record while DENSE_RANK() will rank it as second.Polymorphism means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as a variable, a function or an object to have more than one form.
Polymorphism means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as a variable, a function or an object to have more than one form.
Sealed types cannot be inherited & are concrete. Sealed modifiers can also be applied to instance methods, properties, events & indexes. It can't be applied to static members. Sealed members are allowed in sealed and non-sealed classes.Sealed members are allowed in sealed and non-sealed classes.
Abstract class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies, we call such classes abstract classes. Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods.
Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes with abstract member must also be abstract. Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods. Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes with abstract member must also be abstract. Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes with abstract member must also be abstract. Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class. Abstract classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation. When to use wot depends on various reasons. One being design choice. One reason for using abstarct classes is we can code common functionality and force our developer to use it. I can have a complete class but I can still mark the class as abstract. Developing by interface helps in object based communication.
Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class. Abstract classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation. When to use wot depends on various reasons. One being design choice. One reason for using abstarct classes is we can code common functionality and force our developer to use it. I can have a complete class but I can still mark the class as abstract. Developing by interface helps in object based communication.Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class. Abstract classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation. When to use wot depends on various reasons. One being design choice. One reason for using abstarct classes is we can code common functionality and force our developer to use it. I can have a complete class but I can still mark the class as abstract. Developing by interface helps in object based communication.When you define only function prototype in a base class without and do the complete implementation in derived class. This base class is called abstract class and client won’t able to instantiate an object using this base class. A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be "pure" using the curious "=0" syntax: class Base { public: void f1(); // not virtual virtual void f2(); // virtual, not pure virtual void f3() = 0; // pure virtual };When you define only function prototype in a base class without and do the complete implementation in derived class. This base class is called abstract class and client won’t able to instantiate an object using this base class. A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be "pure" using the curious "=0" syntax: class Base { public: void f1(); // not virtual virtual void f2(); // virtual, not pure virtual void f3() = 0; // pure virtual };A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be "pure" using the curious "=0" syntax: class Base { public: void f1(); // not virtual virtual void f2(); // virtual, not pure virtual void f3() = 0; // pure virtual };The protected keyword is a member access modifier. It can only be used in a declaring a function or method not in the class ie. a class can't be declared as protected class.
A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declare this member. In other words access is limited to within the class definition and any class that inherits from the class A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declare this member. In other words access is limited to within the class definition and any class that inherits from the class A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type. A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type. The internal keyword is an access modifier for types and type members ie. we can declare a class as internal or its member as internal. Internal members are accessible only within files in the same assembly (.dll). In other words, access is limited exclusively to classes defined within the current project assembly. An enum has default modifier as public A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers: public internal private protected internal An interface has default modifier as public A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers: public internal private A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.An enum has default modifier as public A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers: public internal private protected internal An interface has default modifier as public A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers: public internal private A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers: public internal private protected internal An interface has default modifier as public A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers: public internal private A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.An interface has default modifier as public A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers: public internal private A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers: public internal private A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.When you declare a Constructor with Private access modifier then it is called Private Constructor. We can use the private constructor in singleton pattern. If you declare a Constructor as private then it doesn’t allow to create object for its derived class, i.e you loose inherent facility for that class. Example: When you declare a Constructor with Private access modifier then it is called Private Constructor. We can use the private constructor in singleton pattern. If you declare a Constructor as private then it doesn’t allow to create object for its derived class, i.e you loose inherent facility for that class. Example: If you declare a Constructor as private then it doesn’t allow to create object for its derived class, i.e you loose inherent facility for that class. Example: Example: Class A{// some code Private Void A() { //Private Constructor }}Class B:A{//code}B obj = new B();// will give Compilation ErrorBecause Class A constructor declared as private hence its accessibility limit is to that class only, Class B can't access. When we create an object for Class B that constructor will call constructor A but class B have no rights to access the Class A constructor hence we will get compilation error.Because Class A constructor declared as private hence its accessibility limit is to that class only, Class B can't access. When we create an object for Class B that constructor will call constructor A but class B have no rights to access the Class A constructor hence we will get compilation error.No. If you try to create a private class in a Namespace, Compiler will throw a compile time error “Namespace elements cannot be explicitly declared as private, protected, or protected internal”. Reason: The message says it all. Classes can only be declared as private, protected or protected internal when declared as nested classes, other than that, it doesn't make sense to declare a class with a visibility that makes it unusable, even in the same module. Top level classes cannot be private, they are "internal" by default, and you can just make them public to make them visible from outside your DLL.Reason: The message says it all. Classes can only be declared as private, protected or protected internal when declared as nested classes, other than that, it doesn't make sense to declare a class with a visibility that makes it unusable, even in the same module. Top level classes cannot be private, they are "internal" by default, and you can just make them public to make them visible from outside your DLL.In C# : Parent classes may define and implement “virtual” methods(Which is done using the “virtual” keyword), and derived classes can override them(using the “override” keyword), which means they provide their own definition and implementation.At run-time, when user’s code calls the method, the CLR looks up the run-time type of the object, and invokes that override of the virtual method. Thus in your source code when a method of the base class is called it executes the overriden method.In C# : Parent classes may define and implement “virtual” methods(Which is done using the “virtual” keyword), and derived classes can override them(using the “override” keyword), which means they provide their own definition and implementation.At run-time, when user’s code calls the method, the CLR looks up the run-time type of the object, and invokes that override of the virtual method. Thus in your source code when a method of the base class is called it executes the overriden method.Have constructors. Not necessarily for the class inheriting it to Implement all the Methods. Doesn't Support Multiple Inheritance. Where everything is Opposite in the Interfaces.Where everything is Opposite in the Interfaces.
When to Use Abstract Classes and When Interfaces.
Illustrate Server.Transfer and Response.Redirect?
Difference between sealed and static classes
Can we have Sealed Method in abstarct class ?- You need to specify the size of an array at the time of its declaration. It cannot be resized dynamically.
- The members of an array should be of the same data type.
- The size of a collection can be adjusted dynamically, as per the user's requirement. It does not have fixed size.
- Collection can have elements of different types.
- You cannot instantiate an abstract class directly. This implies that you cannot create an object of the abstract class; it must be inherited.
- You can have abstract as well as non-abstract members in an abstract class.
- You must declare at least one abstract method in the abstract class.
- An abstract class is always public.
- An abstract class is declared using the abstract keyword.
- No access specifier is required to define it.
- You cannot pass parameters in static constructor.
- A class can have only one static constructor.
- It can access only static members of the class.
- It is invoked only once, when the program execution begins.
- A class can extend only one abstract class
- The members of abstract class can be private as well as protected.
- Abstract classes should have subclasses
- Any class can extend an abstract class.
- Methods in abstract class can be abstract as well as concrete.
- There can be a constructor for abstract class.
- The class extending the abstract class may or may not implement any of its method.
- An abstract class can implement methods.
- A class can implement several interfaces
- An interface can only have public members.
- Interfaces must have implementations by classes
- Only an interface can extend another interface.
- All methods in an interface should be abstract
- Interface does not have constructor.
- All methods of interface need to be implemented by a class implementing that interface.
- Interfaces cannot contain body of any of its method.
Ranking functions return a ranking value for each row in a partition. All the ranking functions are non-deterministic. The different Ranking functions are as follows:ROW_NUMBER () OVER ([<partition_by_clause>] <order_by_clause>)Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.RANK () OVER ([<partition_by_clause>] <order_by_clause>)Returns the rank of each row within the partition of a result set.DENSE_RANK () OVER ([<partition_by_clause>] <order_by_clause>)Returns the rank of rows within the partition of a result set, without any gaps in the ranking. (Read more here )
EXCEPT clause is similar to MINUS operation in Oracle. The EXCEPT query and MINUS query return all rows in the first query that are not returned in the second query. Each SQL statement within the EXCEPT query and MINUS query must have the same number of fields in the result sets with similar data types. (Read more here)
Usually, when the name of the table or column is very long or complicated to write, aliases are used to refer them.e.g.SELECT VeryLongColumnName col1FROM VeryLongTableName tab1In the above example, col1 and tab1 are the column alias and table alias, respectively. They do not affect the performance at all.VARCHARS are variable length strings with a specified maximum length. If a string is less than the maximum length, then it is stored verbatim without any extra characters, e.g. names and emails. CHARS are fixed-length strings with a specified set length. If a string is less than the set length, then it is padded with extra characters, e.g. phone number and zip codes. For instance, for a column which is declared as VARCHAR(30) and populated with the word ‘SQL Server,’ only 10 bytes will be stored in it. However, if we have declared the column as CHAR(30) and populated with the word ‘SQL Server,’ it will still occupy 30 bytes in database.VARCHAR stores variable-length character data whose range varies up to 8000 bytes; varchar(MAX) stores variable-length character data whose range may vary beyond 8000 bytes and till 2 GB. TEXT datatype is going to be deprecated in future versions, and the usage of VARCHAR(MAX) is strongly recommended instead of TEXT datatypes.In principle, they are the same and are handled in the same way by your application. The only difference is that NVARCHAR can handle unicode characters, allowing you to use multiple languages in the database (Arabian, Chinese, etc.). NVARCHAR takes twice as much space when compared to VARCHAR. Use NVARCHAR only if you are using foreign languages.There are many tips and tricks for the same. Here are few:SQL injection is an attack in which malicious code is inserted into strings that are later passed to an instance of SQL Server for parsing and execution. Any procedure that constructs SQL statements should be reviewed for injection vulnerabilities because SQL Server will execute all syntactically valid queries that it receives. Even parameterized data can be manipulated by a skilled and determined attacker.Here are few methods which can be used to protect again SQL Injection attack:CHECKPOINT process writes all dirty pages for the current database to disk. Dirty pages are data pages that have been entered into the buffer cache and modified, but not yet written to disk.A CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity. (Read more here)A NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.UNIONUNION ALLThe difference between UNION and UNION ALL is that UNION ALL will not eliminate duplicate rows, instead it just pulls all rows from all the tables fitting your query specifics and combines them into a table. (Read more here)The database server uses a B-tree structure to organize index information. B-Tree generally has following types of index pages or nodes:If @@Rowcount is checked after Error checking statement, then it will have 0 as the value of @@Recordcount as it would have been reset. And if @@Recordcount is checked before the error-checking statement, then @@Error would get reset. To get @@error and @@rowcount at the same time, include both in same statement and store them in a local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERRORScheduled tasks let user automate processes that run on regular or predictable cycles. User can schedule administrative tasks, such as cube processing, to run during times of slow business activity. User can also determine the order in which tasks run by creating job steps within a SQL Server Agent job, e.g. back up database and update statistics of the tables. Job steps give user control over flow of execution. If one job fails, then the user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution.The SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA). It is often overlooked as one of the main tools for SQL Server management. Its purpose is to ease the implementation of tasks for the DBA, with its full-function scheduling engine, which allows you to schedule your own jobs and scripts. (Read more here)A local temporary table exists only for the duration of a connection, or if defined inside a compound statement, for the duration of the compound statement.A global temporary table remains in the database accessible across the connections. Once the connection where original global table is declared dropped this becomes unavailable.STUFF function is used to overwrite existing characters using this syntax: STUFF (string_expression, start, length, replacement_characters), where string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and replacement_characters are the new characters interjected into the string. REPLACE function is used to replace existing characters of all occurrences. Using the syntax REPLACE (string_expression, search_string, replacement_string), every incidence of search_string found in the string_expression will be replaced with replacement_string.A PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row, and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity.A UNIQUE constraint enforces the uniqueness of the values in a set of columns; so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.They specify a search condition for a group or an aggregate. But the difference is that HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. Having Clause is basically used only with the GROUP BY function in a query, whereas WHERE Clause is applied to each row before they are part of the GROUP BY function in a queryWhat are the difference between clustered and a non-clustered index?How to get @@ERROR and @@ROWCOUNT at the same time?
SELECT @RC = @@ROWCOUNT, @ER = @@ERROR
Temporary tables are temporary storage structures. You may use temporary tables as buckets to store data that you will manipulate before arriving at a final format. The hash (#) character is used to declare a temporary table as it is prepended to the table name. A single hash (#) specifies a local temporary table.Local temporary tables are available to the current connection for the user, so they disappear when the user disconnects.Global temporary tables may be created with double hashes (##). These are available to all users via all connections, and they are deleted only when all connections are closed.
Once created, these tables are used just like permanent tables; they should be deleted when you are finished with them. Within SQL Server, temporary tables are stored in the Temporary Tables folder of the tempdb database
A common table expression (CTE) is a temporary named result set that can be used within other statements like SELECT, INSERT, UPDATE, and DELETE. It is not stored as an object and its lifetime is limited to the query. It is defined using the WITH statement as the following example shows:
A CTE can be used in place of a view in some instances.
Unique Key Constraint: The column values should retain uniqueness. It allows null values in the column. It will create non-clustered index by default. Any number of unique constraints can be added to a table. Primary Key Constraint: Primary key will create column data uniqueness in the table. It Wont allow Null values. By default Primary key will create clustered index. Only one Primary key can be created for a table. Multiple columns can be consolidated to form a single primary key.
#temp Table (Temporary Table) temp table is a temporary table that is generally created to store session specific data. Its kind of normal table but it is created and populated on disk, in the system database tempdb — with a session-specific identifier packed onto the name, to differentiate between similarly-named #temp tables created from other sessions. The data in this #temp table (in fact, the table itself) is visible only to the current scope. Generally, the table gets cleared up automatically when the current procedure goes out of scope, however, we should manually clean up the data when we are done with it. @table variable table variable is similar to temporary table except with more flexibility. It is not physically stored in the hard disk, it is stored in the memory. We should choose this when we need to store less 100 records. Syntax:
Coalesce returns the first non-null expression among its arguments.
Returns the number of active transactions for the current connection.ACID (an acronymn for Atomicity Consistency Isolation Durability) is a concept that Database Professionals generally look for when evaluating databases and application architectures. For a reliable database all this four attributes should be achieved.
The main difference between RANK and DENSE_RANK comes when they leave gap among records while ranking them.
In OPP’S, polymorphism(Greek meaning “having multiple forms”) is the ablity of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a a function, or an object to have more than one forms. Abstract Class: Posted by: Puneet20884If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.
Posted by: Puneet20884Server.Transfer, transfers the control of a web page, posting a form data, while Response.Redirect simply redirects a page to another page, it can not post a form data to another page. Server.Transfer is more efficient over the Response.Redirect, because Response.Redirect causes a round trip to server as the page is processed once again on the client and a request is made to server there after.
But the browser url is not changed in case of Server.Transfer i.e. Browser history is not modified in using it.
Posted by: Dddsealed classes:
1)we can create their instances, but cannot inherit them
ex:
sealed class demo
{
}
class abc:demo
{
--Wrong
}
2)They can contain static as well as nonstatic members.
static classes:
1)we can neither create their instances, nor inherit them
ex:
static class Program
{
}
2)They can have static members only.
Structure:
1)It is a Value Type
2)Its variable directly contains the data on the stack
3)Each structure variable has its independent copy
of data.
4)One structure cannot inherit other
5)They do not have destructors
6)They do no have explicit parameterless constructors
7)we cannot put sealed /abstract modifiers before the structures.
8)Easier memory management
9)examples:
int, short,long,DateTime,
Point
(predefined)
Uses:
Structures are typically used for handling
small amounts of data or where inheritance, overriding is not required
example: int a=100;
Class
1)It is a reference Type
2)Its variable has references to the data(data is stored in the object created in the heap) .
3)Two Class variables can refer to the same object
4)One class can inherit the other(unless the class is sealed/static)
5)Classes have destructors
6)They can have explicit parameterless constructors
7)Sealed/abstract modifers can be put before classes.
8) Comparitively Difficult memory management
9)example: SqlConnection,DataView(predefined classes)
Classes are typically used where inheritance, overriding is required
or we need to create objects capable of handling large data
example: DataSet,ArrayList can handle large data.
Posted by: PradsirLooking at first site the The Keyword Sealed & Abstract are contradictory to each other..In simple terms we can Say Answer is NO...
Look the code below
using System;
abstract class A
{
public abstract void Hello();
public sealed void Hi();
}
when we will complie the code.. we will get the Compile time Error as below
'A.Hi()' cannot be sealed because it is not an override..
But the Crux is We can have Sealed methods in abstract class when the abstract class is Dervided class .. for Eg.
using System;
class A
{
public virtual void Hello()
{
Console.WriteLine(" Say Hello");
}
}
abstract class B : A
{
public sealed override void Hello()
{
Console.WriteLine(" Say Hi");
}
}
class C : B
{
}
class Demo
{
public static void Main()
{
C c1 = new C();
c1.Hello();// Output is Say Hi
}
}
// Thanks
Array:
Collection:What is operator overloading?Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute.
Example:
class complex {
double real, imag;
public:
complex(double r, double i) :
real(r), imag(i) {}
complex operator+(complex a, complex b);
complex operator*(complex a, complex b);
complex& operator=(complex a, complex b);
}
a=1.2, b=6
A collection can be defined as a group of related items that can be referred to as a single unit. TheSystem.Collections namespace provides you with many classes and interfaces. Some of them are -ArrayList, List, Stack, ICollection, IEnumerable, and IDictionary. Generics provide the type-safety to your class at the compile time. While creating a data structure, you never need to specify the data type at the time of declaration. The System.Collections.Generic namespace contains all the generic collections.Enumeration is defined as a value type that consists of a set of named values. These values are constants and are called enumerators. An enumeration type is declared using the enum keyword. Each enumerator in an enumeration is associated with an underlying type that is set, by default, on the enumerator. The following is an example that creates an enumeration to store different varieties of fruits:enum Fruits {Mango, Apple, orange, Guava}; In the preceding example, an enumeration Fruits is created, where number 0 is associated with Mango, number 1 with Apple, number 2 with Orange, and number 3 with Guava. You can access the enumerators of an enumeration by these values.
A delegate is similar to a class that is used for storing the reference to a method and invoking that method at runtime, as required. A delegate can hold the reference of only those methods whose signatures are same as that of the delegate. Some of the examples of delegates are type-safe functions, pointers, or callbacks.The try block encloses those statements that can cause exception and the catch block handles the exception, if it occurs. Catch block contains the statements that have to be executed, when an exception occurs. Thefinally block always executes, irrespective of the fact whether or not an exception has occurred. The finallyblock is generally used to perform the cleanup process. If any exception occurs in the try block, the program control directly transfers to its corresponding catch block and later to the finally block. If no exception occurs inside the try block, then the program control transfers directly to the finally block.An abstract class is a class that cannot be instantiated and is always used as a base class.
The following are the characteristics of an abstract class:
The basic purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.
Static constructors are introduced with C# to initialize the static data of a class. CLR calls the static constructor before the first instance is created.
The static constructor has the following features:
Abstract Class:
Interface
No comments:
Post a Comment