dot net tips, DotNet tips, .Net Tips,Dot Net tips and tricks,Dot Net Solutions, OOPS Concept in C#,SQL Server, LinQ, Ajax, Java script, JQuery, Server Error details, daily .net tips and tricks , DotNet Interview Questions.
IDictionary in C#
Dictionary represent a collection of keys and values pair of data.
The Dictionary class is a generic class and can store any data types.
The Dictionary class constructor takes two parameters (generic type), first for the type of the key and second for the type of the value.
Dictionary Example program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace iDictionary
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, Int32> sampleDic = new Dictionary<string, int>();
sampleDic.Add("Babu", 1111);
sampleDic.Add("Prabhu", 2222);
sampleDic.Add("Harshad",2223);
Console.WriteLine("IDictionary Value");
Console.ReadKey();
foreach (KeyValuePair<string, Int32> item in sampleDic)
{
Console.WriteLine("Key = {0} ,Value = {1}", item.Key, item.Value);
}
Console.ReadKey();
Console.WriteLine("Thanks");
Console.ReadKey();
Console.WriteLine("----------------");
Console.WriteLine("Dictionary Prperties");
Console.WriteLine("Count: {0}", sampleDic.Count);
Console.WriteLine("----------------");
Console.WriteLine("Dictionary KeyCollection Prperties");
Dictionary<string, Int32>.KeyCollection keys = sampleDic.Keys;
foreach (string key in keys)
{
Console.WriteLine("Key : {0}", key);
}
Console.WriteLine("----------------");
Console.WriteLine("Dictionary ValueCollection properties ");
Dictionary<string, Int32>.ValueCollection val = sampleDic.Values;
foreach (Int32 item in val)
{
Console.WriteLine("Value : {0}", item);
}
Console.ReadKey();
}
}
}
The Dictionary class is a generic class and can store any data types.
The Dictionary class constructor takes two parameters (generic type), first for the type of the key and second for the type of the value.
Dictionary Example program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace iDictionary
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, Int32> sampleDic = new Dictionary<string, int>();
sampleDic.Add("Babu", 1111);
sampleDic.Add("Prabhu", 2222);
sampleDic.Add("Harshad",2223);
Console.WriteLine("IDictionary Value");
Console.ReadKey();
foreach (KeyValuePair<string, Int32> item in sampleDic)
{
Console.WriteLine("Key = {0} ,Value = {1}", item.Key, item.Value);
}
Console.ReadKey();
Console.WriteLine("Thanks");
Console.ReadKey();
Console.WriteLine("----------------");
Console.WriteLine("Dictionary Prperties");
Console.WriteLine("Count: {0}", sampleDic.Count);
Console.WriteLine("----------------");
Console.WriteLine("Dictionary KeyCollection Prperties");
Dictionary<string, Int32>.KeyCollection keys = sampleDic.Keys;
foreach (string key in keys)
{
Console.WriteLine("Key : {0}", key);
}
Console.WriteLine("----------------");
Console.WriteLine("Dictionary ValueCollection properties ");
Dictionary<string, Int32>.ValueCollection val = sampleDic.Values;
foreach (Int32 item in val)
{
Console.WriteLine("Value : {0}", item);
}
Console.ReadKey();
}
}
}
this keyword
The this is a keyword, It refers to the current instance of the class.
It can be used to access members from within constructors,instance accessors instance methods and instance successor.
public class Demo4this
}
static void Main(string[] args)
It can be used to access members from within constructors,instance accessors instance methods and instance successor.
public class Demo4this
{
int age;
string name;
public Demo4this(int age, string name)
{
this.age = age;
this.name = name;
}
public void Show()
{
Console.WriteLine("Your Name : " + name);
Console.WriteLine("Your Age :" + age.ToString());
}}
static void Main(string[] args)
{
int age1;
string name1;
Console.WriteLine("Enter your name : ");
name1=Console.ReadLine();
Console.WriteLine("Enter your age : " );
age1=Int32.Parse(Console.ReadLine());
Demo4this obj = new Demo4this(age1, name1);
obj.Show();
Console.ReadLine();
Console.ReadLine();
}
}
}
Size of stored procedure
Stored procedures are special objects
available in sql server
It
is a collection of transact sql statements that can take or return user
supplied parameters.
It s a p recompiled statements where all the preliminary parsing operations are performed and the statements are ready for execution.
Maximum size of stored procedure is 128 MB.
Check isalphanumeric in sql server
ALTER FUNCTION dbo.ISALPHANUMERIC
(
@columnfield VARCHAR(5000)
)
RETURNS VARCHAR(5000)
AS
BEGIN
DECLARE @splcharposition INT
SET @splcharposition = PATINDEX('%[^0-9A-Za-z]%', @columnfield)
WHILE @splcharposition > 0
BEGIN
SET @columnfield = STUFF(@columnfield, @splcharposition, 1, '')
SET @splcharposition = PATINDEX('%[^0-9A-Za-z]%', @columnfield)
END
SET @columnfield = @columnfield
RETURN @columnfield
END
GO
(
@columnfield VARCHAR(5000)
)
RETURNS VARCHAR(5000)
AS
BEGIN
DECLARE @splcharposition INT
SET @splcharposition = PATINDEX('%[^0-9A-Za-z]%', @columnfield)
WHILE @splcharposition > 0
BEGIN
SET @columnfield = STUFF(@columnfield, @splcharposition, 1, '')
SET @splcharposition = PATINDEX('%[^0-9A-Za-z]%', @columnfield)
END
SET @columnfield = @columnfield
RETURN @columnfield
END
GO
Multiple onload event in dot net
Definition
Once a page has been loaded 'onload' event executes a JavaScript immediately.
We can use onload function in number of ways:
1. <body onload="load1()">
2. <element onload="SomeJavaScriptCode">
3. object.onload="SomeJavaScriptCode"
4. window.onload = load;
function load1() {
alert("This is the first.");
}
<frameset onload="framload()">
Once a page has been loaded 'onload' event executes a JavaScript immediately.
We can use onload function in number of ways:
1. <body onload="load1()">
2. <element onload="SomeJavaScriptCode">
3. object.onload="SomeJavaScriptCode"
4. window.onload = load;
function load1() {
alert("This is the first.");
}
onLoad Event handlers Examples
<frameset onload="framload()">
<img src="logo.gif" onload="imgload()">
USE of onload
This is used to invoke JavaScript function after the page or an image has finished loading.
Subscribe to:
Posts (Atom)