Saturday, January 30, 2010

LINQ queries for integer and string array

In this post i will show some basic queries which we can make on the array in .Net environment.

First of all we will see LINQ query for integer array.

 

   1:  int[] intArray = { 1, 5, 7, 15, 19, 20 };
   2:  var query = from i in intArray
   3:              where i % 5 == 0
   4:              select i;

 

In above example i had defined an integer array as intArray. above LINQ query will select all the integer value which can be divisible with 5.

So its output will be {5, 15, 20}

This was basically searching functionality. Now if you need to sum all the values within array, you can achieve it with below LINQ statement

   1:  int sum = intArray.Sum();

And it will give you sum of all the array

For average the array in LINQ you need to write

   1:  int avg = intArray.Average();

 

Now lets take another example of a string array.

   1:  string[] strArray = {"red", "blue","green", "black", "yellow" };
   2:  var query = from s in strArray
   3:              where s.StartsWith("b")
   4:              select s;

 

Now in this example i have an array of string containing various color name. Above LINQ query will select all the name that starting with be.

So its output will be {“blue”, “black”}

LINQ provide developers a great way to use logic that we can build in C# and LINQ will handle it.

There are much more functionality LINQ provides like concate, reverse, first, last, etc.

Google transliteration IME in 14 new indian languages - Fyoq News

Check out this article

 
 

Sent to you by Nirav Bhatt via Google Reader:

 
 

via Sci/Tech - Google News on 1/28/10


Little About (blog)

Google transliteration IME in 14 new indian languages
Fyoq News
Today Google India announced officially the availablity of Google transliteration in 14 languages. These fourteen Indian languages are Arabic, Bengali, Farsi (Persian), Greek, Gujarati, Hindi, Kannada, Malayalam, Marathi, Nepali, Punjabi, Tamil, ...
Google intros language translator applicationCIOL
Google launches applications to type in 14 languagesThe Hindu

all 16 news articles »

 
 

Things you can do from here:

 
 

Wednesday, January 27, 2010

Introduction to LINQ

Language Integrated Query (LINQ) is a great tool shipped with .net framework 3.5. With LINQ you can achieve a lot more functionality and save a lot of your development time.

What LINQ support?

LINQ to SQL Server: With LINQ you can directly connect to SQL server and write down your queries in C#. When you use LINQ to SQL classes, LINQ will automatically generate classes for your tables in the SQL server.

LINQ to XML: With LINQ to XML you can achieve XML programming in .Net framework.

LINQ to Dataset: With LINQ to Dataset you can connect LINQ to ADO.Net Databases

LINQ to Objects: With QINQ to Objects you can achieve any query on the collection of objects. This can help you to avoid loop for multiple conditions over a collection. You can use LINQ to Objects over Array, List etc.

Next article will be on basic LINQ queries.

Saturday, January 2, 2010

AJAX 4.0, ASP.Net 4.0, Visual Studio 2010 Beta

Hello friends, Microsoft has released Visual Studio 2010 beta 2 with ASP.Net 4.0, Ajax 4.0, MVC, Routing and more features.

I had looked at the overview of it and hence sharing it with you.

Output caching in ASP.Net 4

In ASP.NET 4 you can configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. Because of this you can create custom output-cache providers for diverse persistence mechanisms, which can include local or remote disks, cloud storage, and distributed cache engines.

Auto Start Application Pool

Basically in iis 7 when any website have its first request it will take time to initialize the site and its data. Now in IIS7.5 with ASP.Net 4 you can set start the application automatically. So when your web site is started, it will initialized automatically and your application pool will be in Always Running mode.

Permanently Redirecting a Page

Previously we were using code to move a page permanently to another url with 301 redirection. In ASP.Net 4 Microsoft has provided RedirectPemanent.

Shrinking Session State

If you are not using in process session state you have a new feature in ASP.Net 4, you can compress the session state with compressionEnabled="true".

Range of Allowable URLs in HttpRuntime

Now you can specify allowed url length and query string length with maxRequestPathLength="260" and maxQueryStringLength="2048"

Valid Characters in URL in HttpRuntime

You can now specify invalid characters in your website with requestPathInvalidChars="<,>,*,%,&,:,\"

Request Validation in HttpRuntime

Now in ASP.Net 4 you can create your own request validator with requestValidationType="MyCustomValidator"

Header, URL and Html encoding in HttpRuntime

You can create your own encoder class for encoding for HTTP Header, URL and Html with encoderType="MyCustomEncoder"

Performance Monitoring

ASP.Net 4 also allow to enable performance monitoring out of the application domain.

 

There are  more features which I need to explore. Will try to post it asap.