select distinct sno ,
STUFF((Select ','+Scity
from @Test T1
where T1.sno=T2.sno
FOR XML PATH('')),1,1,'') from @Test T2
Result:
feature
" parameter of window.open()
to manipulate its interface. Most features support a value of true
or false
,
though in general, simply including the name of the feature implies it
should be added to the window (yes), while not including it means it
shouldn't (no). Separate each feature with a comma (,).Feature | Description |
channelmode |
Specifies if window should be opened in channel mode. IE only. |
fullscreen |
Specifies if window should be opened in full screen mode. IE only. |
height |
Specifies the height of the window. |
left |
Specifies the x coordinates of the window in pixels. IE only. See "screenX " as well. |
location |
Specifies if the location bar of the window should be included. |
menubar |
Specifies if the menu bar of the window should be included. |
resizable |
Specifies if window should be resizable. |
screenX |
Specifies the x coordinates of the window in pixels. NS only. See "left " as well. |
screenY |
Specifies the y coordinates of the window in pixels. NS only. See "top " as well. |
scrollbars |
Specifies if window should contain scrollbars |
status |
Specifies if the status bar of the window should be included |
toolbar |
Specifies if the toolbar of the window (i.e., reload button) should be included. |
top |
Specifies the y coordinates of the window in pixels. IE only. See "screenY " as well. |
width |
Specifies the width of the window. |
/* Delete Duplicate records */
WITH CTE (COl1,Col2, DuplicateCount)
AS
(
SELECT COl1,Col2,
ROW_NUMBER() OVER(PARTITION BY COl1,Col2 ORDER BY Col1) AS DuplicateCount
FROM DuplicateRcordTable
)
DELETE
FROM CTE
WHERE DuplicateCount > 1
GO
----------------------------------------------------------------------------------------
DECLARE @TableName VARCHAR(255)
DECLARE @sql NVARCHAR(500)
DECLARE @fillfactor INT
SET @fillfactor = 80
DECLARE TableCursor CURSOR FOR
SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
FROM sys.tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
EXEC (@sql)
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
GO
-------------------------------------------------------------------------------------------
Init
method is fired. Most common functionalities
implemented in this method include:OnClick
event of the
Button can be registered in the Init
rather
than specifying in the OnClick
property
of the Button in the aspx page.Load
event. After
the Page
raises this event,
it loads view state for itself and all controls, and then processes any
postback data included with the Request
instance.Page
calls the OnLoad
event method on the Page
, then recursively does the same for
each child control, which does the same for each of its child controls until
the page and all controls are loaded. Use the OnLoad
event method to set properties in controls and
establish database connections.Button
control's
Click
event or a TextBox
control's TextChanged
event.PreRender
event
also occurs for each control on the page. Use the event to make final changes
to the contents of the page or its controls.ViewState
has
been saved for the page and for all controls. Any changes to the page or
controls at this point will be ignored.Page
object calls the Render
method of each control at this
stage. All ASP.NET Web server controls have a Render
method that writes out the control's markup that
is sent to the browser.
Abstract
|
Virtual
|
No
Keyword
|
|||||||||||||
Can have
implementation?
|
No
|
Yes
|
Yes
|
||||||||||||
Can override?
|
Must
|
Can but not a must
|
You can declare a new
method with the same name
|
||||||||||||
Which keyword to use to
provide new implementation in the concrete class?
|
override
|
override
|
No keyword needed
|
||||||||||||
Concrete implementation
|
The parent
implementation will be called only if no implementation is provided in the
concrete class
|
Parent implementation
|
|||||||||||||
Concrete implementation
|
Concrete implementation
|
The parent
implementation will be called only if no implementation is provided in the
concrete class
|
|||||||||||||
Interface
•Interface nothing but skeleton of the class
•We cant create object for interface
•It s a Pure abstraction
•Pure abstraction means you cannot have
concrete methods
•Interfaces should not have any concrete
methods, it should only have method declarations.
A method with definition is concrete method
In which
scenario we use Interfaces:
•If your child classes should all implement a
certain group of methods/functionalities but each of the child classes is free
to provide its own implementation then use interfaces.
•For e.g. if you are implementing a class
hierarchy for vehicles implement an interface called Vehicle which has
properties like Color MaxSpeed etc. and methods like Drive(). All child
classes like Car Scooter Airplane Solar Car etc. should derive from this base
interface but provide a separate implementation of the methods and properties
exposed by Vehicle
Which one is advantage over another:
•Interface has advantage over Abstract class.
Since you can not use abstract class for already inherited class. But you can
use interface for already inherited class.
Difference
between Abstract and Interface:
•We declared 10 methods in interface, now we
should implement all 10 methods. But we want implement 2 methods only.
•How?
•Example.
Sealed
Class:
•Sealed classes are used to restrict the
inheritance feature of object oriented programming
•A sealed class cannot be used as a base
class.
•Sealing a class means one cannot derive
from it.
•A method means one cannot override it.
•Example.
Polymorphism
•Polymorphism means many forms.
•Polymorphism is the ability to process
objects differently depending on their data types.
•Polymorphism is the ability to redefine
methods for derived classes.
Polymorphism provides
following features:
•It allows you to invoke methods of derived
class through base class reference during runtime.
•It has the ability for classes to provide
different implementations of methods that are called through the same name.
Polymorphism
Polymorphism is of two
types:
1.Compile time polymorphism/Overloading
2.Runtime polymorphism/Overriding
Compile Time Polymorphism
• Compile time polymorphism is method
overloading. It is also called early binding.
• In method overloading method performs
the different task at the different input parameters.
Runtime Time Polymorphism
• Runtime time polymorphism is done using
inheritance and virtual functions. Method overriding is called runtime
polymorphism. It is also called late binding
Overloading:
•Overloading a method simply involves
having another method with the same prototype.
Overriding
•To change the behavior of the method for the
derived class
Note
•Method overloading has nothing to do with
inheritance or virtual methods.
Following are examples of
methods having different overloads:
•void area(int side);
•void area(int l, int b);
•Void area(int l, double b, int c)
•Void area(double b, int l, int c)
•void area(float radius);
Polymorphism
When and why
to use method overloading
• Use method overloading in situation where
you want a class to be able to do something, but there is more than one
possibility for what information is supplied to the method that carries out the
task.
• You should consider overloading a method
when you for some reason need a couple of methods that take different
parameters, but conceptually do the same thing.
•Example
•
• Void Area(int a)
//Square
•Void Area(int h,int w)
//Rectangle
•Void Area(int a, int l, int w)
//Cylinder
•Void Area(int pi, int r ,
int
l) //Cone
•Void Area(int pi, int r
) //Circle
When and why
to use method overriding
•Its obvious that when we do inheritance
between two classes, all the methods and properties of the first class are
derived to the other class so that this becomes the child class which
adobes all the functionality of base class. It can also possesses its own
separate methods.
•But there is a big problem in inheriting the
second class to the first class as it adobes all the methods same as the base
class has, which means that after inheritance both(base class& child
class) have the methods of same name and same body as shown in this example
•Example,
we
have seen example of overriding
•how many overload of a method we can have?
•
•What?
•Type?
•When?
•Overloading?
•Overriding?
•static binding?
•Late binding?
String
and String Builder:
•Strings are Immutable
(Not Modifiable). If you try to modify the string it actually creates a new
string and the old string will be then ready for garbage collection.
•String Builder when instantiated, creates a
new string with predefined capacity and up to that capacity it can accommodate
string without needing to create a new memory location for the string....i
mean it is modifiable and can also grow as and when needed.
•The most common operation with a string is
concatenation. This activity has to be performed very efficiently. When we use
the "String" object to concatenate two strings, the first string is
combined to the other string by creating a, and then the old string is deleted.
This process is a little long. Hence we say "Strings are immutable".
•When we make use of the "String
Builder" object, the Append method is used. This means, an insertion is
done on the existing string. Operation on String Builder object is faster than
String operations, as the copy is done to the same location. Usage of String
Builder is more efficient incase large amounts of string manipulations have to
be performed.
•String Example:
String
myString=”Welcome”;
myString=myString+”Software
Team”;
•String builder Example
StringBuilder sb =
new StringBuilder();
sb.Append("raj");
sb.Append("mani");
String
builder
Methods:
Ex:
Append, insert, remove, replace and Tostring.
Performance:
1.Avoid short appends.
2.Cache objects.
3.Avoid some data types.
4.Data Types
5.Append Chars
6.Stringbuilder Comparison
7.Append integers
8.Capacity
●
9.Example:
http://www.dotnetperls.com/stringbuilder
Override: When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class.
New: If you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it.
If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).
Override: used with virtual/abstract/override type of method in base class
New: when base class has not declared method as virtual/abstract/override
Static
class , method and variables
12 Features of Static class
1.A static class cannot be instantiated
2.Static class can have only static members.
3.Member of the Static class can be accessed by
class name itself.
4.Static class is sealed. So static class
cannot be inherited.
5.Static class contains only static
constructors.
6.Static class cannot have instance
constructors.
7.Static class can only be inherited only from
object class.
8.Static class is preceded by keyword static.
9.Static constructor of static class called
only once.
10.Static class has private constructors
11.Static classes cannot implement interfaces
12.static classes cannot have instance
constructors
Notable Points here are:
•A static method can be invoked directly from
the class level
•A static method not requires any class object
•Any main() method is shared through entire
class scope so it always appears with static keyword.
Static method
•A static method can access only static
fields.
•A static method cannot access non static
fields.
•A static method cannot be called using object
of a class
•A static method can be called using class
name.
• Static field can be used using class name.
•Static method cannot be override or overload.
•We can't put access modifier in static
constructor?
Constructor:
http://www.programcall.com/16/csnet/constructor-types-with-example-programs-in-csnet.aspx
•A static constructor does not take access
modifiers or have parameters.
•A static constructor is called automatically
to initialize the class before the first instance is created or
any static members are referenced.
•A static constructor cannot be called
directly.
•The user has no control on when the static
constructor is executed in the program.
•A typical use of static constructors is when
the class is using a log file and the constructor is used to write entries to
this file.
•Static constructors are also useful when
creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.
•If a static constructor throws an exception,
the runtime will not invoke it a second time, and the type will remain
uninitialized for the lifetime of the application domain in which your program
is running.
http://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx
what
is difference between instance constructor and Static constructor in C#.Net
Main Differences are :
• A Constructor declare using Static
modifier was known as Static Constructor. Rest of all were Instance
Constructor.
•Static Constructor are responsible for
initialization of static variables and Instance Constructor for initialization
of instance constructor.
•A static constructor is called only one's in
the execution of a class. Where as instance constructor gets called each time
we create the object of the class. if no object is created. It is not called at
all.
•static constructor is the first block of
which gets executed under the class.
•A static constructor can't be parameterized
because explicit calling of the constructor is not done.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1{
class staticconstructor
{
static staticconstructor()
{
Console.WriteLine("static constructor");
}
staticconstructor()
{
Console.WriteLine("non-static constructor");
}
static void
Main()
{
Console.WriteLine("main method");
staticconstructor st = new staticconstructor();
staticconstructor st1 = new staticconstructor();
Console.ReadLine();
}
}
}
o/p: static constructor, main method
, non-static constructor , non-static constructor
Notable Points here are:
•A static method can be invoked directly from
the class level
•A static method not requires any class object
•Any main() method is shared through entire
class scope so it always appears with static keyword.
Static method
•A static method can access only static
fields.
•A static method cannot access non static
fields.
•A static method cannot be called using object
of a class
•A static method can be called using class
name.
• Static field can be used using class name.
•Static method cannot be override.
•We can't put access modifier in static
constructor?
public static string GetData(int CustomerID) {
Page page
= HttpContext.Current.Handler as Page;
if (page != null)
{
string outputToReturn = "";
page.ViewState["MyVal"]="Hello";
return outputToReturn;
//btw,
what a strange method!
}
}
collection
Four important categories
•Index based
–Array
–List
•Key value pair
–Hash
table
–Sort
list
•Prioritized collection
–Queue
–Stack
•Specialized collection
–String
collection
–Hybrid
dictionary
array and array list
Hash
Table and Array List
hash table
HashTable:
HashTable stores a key-value pair type collection of
data.
NOTE:
Both key and value are object
the
key values are UNIQUE
Functions:
•Clear
•Remove
•Containskey
•Containsvalue
•Contains
•Add
Variables
•Count
Remove:
hash_table_name.Remove(key);
Remove All Values:
hash_table_name.Clear()
ContainsKey(Key)
its returns true or false..
ContainsValue(value):
its
returns true or false..
EXAMPLE
Hashtable sampleHt = New Hashtable sampleHt.add("US",”united States”) // Area- key. 1000 - value sampleHt.add("IND",”India”)
// To fetch the value we can use name, for example
String countryname=convert.tostring(sampleHt[“US”]);
sampleHt.remove(“US”);
IDictionaryEnumerator idic= sampleHt.GetEnumerator();
while(idic.MoveNext())
{
idic.Value.ToString();
}
|