Thursday, October 28, 2010

GAC( Global assambly cache)

Hi guys,
When we develop any application  By .net technology You just see the
Using System name space. Did you think from where its come without reference any dll as add reference.
Actually all the main name-space which is required in every project reside under the GAC(Global assembly cache).
           Now the question is arises from where the gac is coming..................
Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.
Gac is reside under the c://window//assembly(all the usefull dll file reside under this folder)

Monday, October 25, 2010

Linq for Beginner

Language Integrated Query,  is a set of Microsoft .NET Framework language enhancements and libraries
built by Microsoft to make working with data ex Access record from Table by using object.
Example:
List<Contact> contacts = Contact.SampleData();
// perform the LINQ query            line 2
var query = from c in contacts
                  orderby c.State, c.LastName
                        group c by c.State;
// write out the results
foreach (var group in query)
{
Console.WriteLine(”State: “ + group.Key);
foreach (Contact c in group)
Console.WriteLine(” {0} {1}”,
c.FirstName, c.LastName);
}
 Here in example line 2 we can easily find out how Database table use as a object.
from c in contracts here contracts is a list which contain lot of record we are assemble all the record in variable c.  means here c is used as a Object which contain the table data. c.state show the data field in contact list.( In linq all the quarry Write down  just opposite to sql. The same quarey write down in sql as.
select state,lastname from contract
order by state group by LastName.

 LINQ to Objects allows .NET developers to write “queries” over collections of objects.working with collections of objects meant writing a lot of looping code using for loops or foreach loops.
 As simple example
int[] nums = new int[] { 0, 4, 2, 6, 3, 8, 3, 1 };
var result = from n in nums
where n < 5
orderby n
select n;
foreach (int i in result)
Console.WriteLine(i);
Output 2-3
0
1
2
3
3
4
Listing

Note----> Select-From-Where-OrderBy,(we follow this format when using SQL!!!!!!
                 From-Where-OrderBy-Select,(Just reverse in LINQ)



Query joins two collections
List<Contact> contacts = Contact.SampleData();
List<CallLog> callLog = CallLog.SampleData();
var q = from call in callLog
join contact in contacts on
call.Number equals contact.Phone
select new {
contact.FirstName,
contact.LastName,
call.When,
call.Duration
};
foreach (var c in q)
Console.WriteLine(
”{0} – {1} {2} ({3}min)”,
c.When.ToString(”ddMMM HH:m”), c.FirstName,
c.LastName, c.Duration);
Output 2-7
07Aug 08:
Here we are fetch all record from Table contacts and callLog(In which phone no field is common on behalf of this we are join both table and fetch data according to our requirement.

 List<Contact> contacts = Contact.SampleData();
List<CallLog> callLog = CallLog.SampleData();
var q = from call in callLog
where call.Incoming == true
group call by call.Number into g
join contact in contacts on
g.Key equals contact.Phone
orderby contact.LastName, contact.FirstName 

The Let keyword:
The let keyword enables you to keep the result of an expression
(a value or a subquery) in scope throughout the rest of the query expression
being written. Example
int [] values=new int []  {2,4,5,6,76,5};
var query = from i in values
        let doublei = 2 * i
        select doublei;
        Console.WriteLine(query);

The new form of Linq

List<Contact> contacts = Contact.SampleData();
var q = contacts.Where(c => c.State == ”WA”)
.OrderBy(c => c.LastName)
.ThenBy(c => c.FirstName);
foreach (Contact c in q)
Console.WriteLine(”{0} {1}”,
c.FirstName, c.LastName);

The simple form Linq as i am thinking

List<Contract> contacts= Contract.SampleData();  (here sample data just collect the ample data)
var q= from con in contacts
           where con.state=='wa'
            orderby con.LastName
            select con;
Cosole.WriteLine(q);
The simple example how Linq work with sql joining  
                    
List<Contact> contacts = Contact.SampleData();
List<CallLog> callLog = CallLog.SampleData();
var q = (from call in callLog
join contact in contacts on
call.Number equals contact.Phone
orderby call.When descending
select new
{
contact.FirstName,
contact.LastName,
call.When,
call.Duration
}).Take(5);
foreach (var call in q)
Console.WriteLine(”{0} - {1} {2} ({3}min)”,
call.When.ToString(”ddMMM HH:m”),
call.FirstName, call.LastName, call.Duration);

Where Filter Using a Lambda Expression
All lambda expressions use the lambda operator =>, which is read as "goes to".
use this link  http://msdn.microsoft.com/en-us/library/bb397687.aspx

string[] animals = new string[] { ”Koala”, ”Kangaroo”,“Spider”, “Wombat”, “Snake”, “Emu”};
var q = animals.Where(
                                       a => a.StartsWith(“S”) && a.Length > 5);
foreach (string s in q)

{
Console.WriteLine(s);

}
here a=> a.StartWith  show d lambda experison.

string[] animals = new string[] {"Koala", "Kangaroo" };
var q = from a in animal where a.StartsWith("K") && a.Length > select a;
foreach (string s in q)
Console.WriteLine(s);
New form of linq(use function calling)

string[] animals = new string[] { ”Koala”, ”Kangaroo”,
”Spider”, “Wombat”, “Snake”, “Emu”, “Shark” };
var q = from a in animals
where IsAnimalDeadly(a)   // in where clause call the function//
select a;
foreach (string s in q)
Console.WriteLine(“A {0} can be deadly.”, s);

public static bool IsAnimalDeadly(string s)  //Here define the Method
{
string[] deadly = new string[] {“Spider”, “Snake”,
”Shark”, “Sting-Ray”, “Jellyfish”};
return deadly.Contains(s);
}
Output
A Spider can be deadly.
A Snake can be deadly.
A Shark can be deadly.
A Sting-Ray can be deadly.
A Jellyfish can be deadly.

Filtering by Index Position
The
zero-based index position can be passed into a lambda expression predicate
by assigning a variable name as the second argument.
To surface the index position, a lambda expression
must be used, and this can only be achieved using the extension method
syntax.
Example of Index position

string[] animals = new string[] { "Koala", "Kangaroo",
"Spider", "Wombat", "Snake", "Emu", "Shark",
"Sting-Ray", "Jellyfish" };
var q = animals.Where((a, index) => index % 2 == 0);
foreach (string s in q)
Console.WriteLine(s);




Monday, October 4, 2010

Cross browser compatibility

Most important issue in developing web site is cross browser supporting facility.Means o/p of one page is looking different in some browser like mozila,IE7,IE8 crome,safari etc.
so developers test the web pages on different browser and create the different css file as per requirement and including in their page as example...........
<head id="head1" runat="server">
  
    <!--[if IE 8]><!-->
    <link href="../Styles/IE8.css" rel="Stylesheet" type="text/css" />
    <!--<![endif]-->

    <meta HTTP-equiv="content-type" content="text/ht-ml; char-set=utf-8" />
    <link h ref=' http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:light,regular'
        rel='style sheet' type='text/css'>
</head>
This css only working in IE 8(internet explorer 8) and same as create many css file like
IE7.CSS,   MOZ.CSS,  CROME.CSS.

NOTE---> One Thing i am notice today is that IIS(Internet Information Server) store the web page changes so on account of this it show the previous  page so avoid these think programmer have to delete the browsing history of all the web browser which are using for testing and also reset the setting of Browser. 
Thanks