Problem:
Possible Solutions to problem:
- With normal for loop
- With lamda expression and linq
Jalpesh Vadgama's blog about technologies and life.
Full Stack Developer with 12+ years of experience
I can help you getting your projects done. I'm available for new work
Hire Me
Linq operator provides great flexibility and easy way of coding. Let’s again take one more example of distinct operator. As name suggest it will find the distinct elements from IEnumerable. Let’s take an example of array in console application and then we will again print array to see is it working or not. Below is the code for that. In this application I have integer array which contains duplicate elements and then I will apply distinct operator to this and then I will print again result of distinct operators to actually see whether its working or not.
using System;Below is output as expected..
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Experiment
{
class Program
{
static void Main(string[] args)
{
int[] intArray = { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5 };
var uniqueIntegers = intArray.Distinct();
foreach (var uInteger in uniqueIntegers)
{
Console.WriteLine(uInteger);
}
Console.ReadKey();
}
}
}
That’s cool..Stay tuned for more.. Happy programming.
C# 4.0 has one new cool features which is the named parameter. Suppose you have so many parameter in function and when you call them its hard to remember the sequence of the code now with the named parameter you can have name of the parameter with value like Parameter:value and one another cool feature of the name parameter is the you don't need to pass the parameter in exact sequence. Let see the following example
In above example I am having a function called square with two parameter min and max and having a function which will return the square of the given range between min and max. See the for each loop carefully. I have named parameters and another thing you will notice that i have changed the sequence of parameter but still its working fine. So this is a very cool new feature from the C# 4.0.
Happy Programming...
Microsoft visual studio express editions are light weight IDE provided free by Microsoft and also having almost all the functionality of its big brother Microsoft Visual Studio Professional edition except few. My pc is bit old now Its P4 and its having only 1gigs of ram so the express edition are the best suited for pc like mine. Microsoft has recently provided the beta 2 version of Microsoft new generation IDE called Visual Studio Twenty Ten(2010).
There are lots of changes from visual studio 2008 express edition and Microsoft Visual Studio 2010 Express edition. The first changes you will notice is the brand new splash screen and brand new colored logo for visual studio.
Another thing you will notice is the look and fill of IDE. It all looks like blue every where. Its is best suited for the Microsoft forthcoming operating system Microsoft Windows 7.
Another the difference is the create new project window which is bit stylish and having more options compare the to the visual studio 2008. There are two new things in new project dialog the first one the windows azure tools which is Microsoft's new steps towards the could computing(I will blog about this later one). and another thing is the Silver light application option. Now you can create three kind of application with the Microsoft SilverLight Application
Another difference is the default font for the IDE earlier it was Courier New and now its Consolas which is the next generation programming font. Which is more visual than the other fonts.
Another major difference is when you create a asp.net web application then its now having more default folders compare to visual studio 2008. There are site.master is also there and some default style sheet just like asp.net mvc applications. You will have default login control like asp.net mvc application. There are two more folder scripts and styles. In style you will have default style sheet for the application. Another folder is for the scripts which are having default JQuery as per earlier announcement Microsoft and JQuery will go together.
Another new things in Microsoft Visual Studio 2010 Visual Web Developer Expression edition is the Tool Setting menu which are having three setting by default.
All the three option will have different setting for solution explorer and all other stuff. Another new thing is visual web developer 2010 express edition having multi monitor support which is not there in earlier express editions.Visual web developer express also having windows presentation foundation code editor.
Another cool feature is the maximized windows in design view now you will have whole window is maximized in design view hiding other windows. So you visually look all the control more better. Another cool thing is the percentage dropdown through which you can set all screen by percentage as per your requirement.
There are lots of more features like Improved css compatibility,HTML and Javascript snippets,support for asp.net mvc application and support for multi target etc. I will blog about each feature in much more detail. T
If you still not downloaded the future version of visual studio express edition 2010 then you can download it from the following link.
In earlier post i have mentioned that how to send the email using new System.Net.Smtpmail with asp.net 2.0 or higher version. Now lets learn how to send the mail with the secure service layer in the asp.net.
Security is the one of the most important requirement in today’s world as you are doing your business online you have keep secure from other wrong elements. Secure service layer add an
extra layer of security to your web application and sending mail with the SSL with tighten your security for mails. Your emails are more secure then ever and your valuable information will not going to wrong hands.
Here is the code from which we can send the email with the secure service layer. As i have mentioned in earlier post you need to to send email with authentication to use SSL. So you need to write following code. First you need to create message like following..
Then you have to sent message with following code.MailAddress fromAddress = new MailAddress("from@site.com","Nameofsendingperson");message.From = @”fromAddress”;//here you can set address
message.To.Add("mailto:to@site.com%22%29;//");//message.Subject = "Sending email with ssl";
message.CC.Add("cc@site.com");//ccing the same email to other email addressmessage.Bcc.Add(new MailAddress("bcc@site.com"));//here you can add bcc addressmessage.IsBodyHtml = true;//To determine email body is html or notmessage.Body =@"Plain or HTML Text";
System.Net.Mail.SmtpClient mailClient =new System.Net.Mail.SmtpClient("your smptp","ssl port");//This object stores the authentication values
System.Net.NetworkCredential basicCrenntial =new System.Net.NetworkCredential("username", "password");mailClient.Host = "Host";
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicCrenntial;// You have to add one other properties for SSL
mailClient.EnableSSL=true;
mailClient.Send(message);
Microsoft.NET Framework 4.0 beta version is out now. Let’s see the what’s new in asp.net 4.0 for the developer purpose. There are lots of features are there. Some of them are following.
1) Extensible Output Caching:
ASP.NET 4.0 adds an extensibility to output caching now you can create your cache provider and will can use this provider for the caching. So now you can use your own data source for you caching.
2) AutoStart Webapplication
Before asp.net 4.0 you have to use application_load or application_start event for the extensive data processing before application pages loads. But now you can use auto start features of asp.net 4.0. A new scalability feature named auto-start that directly addresses this scenario is available when ASP.NET 4.0 runs on IIS 7.5 on Windows Server 2008 R2. The auto-start feature provides a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP requests.
3) Permanently Redirecting a page
Before asp.net 4.0 you need to use response.redirect method to go to another page from new page. ASP.NET, developers have traditionally handled requests to old URLs by using by using the Response.Redirect method to forward a request to the new URL. However, the Redirect method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs. Now permanent redirect will solve this. Its will also benefit for the Search Engine Optimization.
4) Compressed Session State:
ASP.NET 4.0 will have new option for session stored in sql server or in state service. You can compress your serialized session using GZip Compression
5) Page.Keywords and Page.Description Properties
In asp.net 4.0 now you can create dynamic keywords and description for a page using Page.Keywords and Page.Description Properties
6) Enabling View state for Individual Controls
In earlier version of the asp.net if you disable your parent control view state it will disable your child control view state but now with asp.net view state is not dependent on parent child control view state.
7) Routing in asp.net 4.0
Now you can have build in routing for your pages. You don’t have to write your url rewriting modules. It introduces a WebFormRouteHandler routing class which will take care of routing.
8) ClientID
In earlier asp.net version clientId is system generated and if you want to change you have to override it . ASP.NET by default generated a big string for the clientid which will increase your html kb. With asp.net you have small client id using different options Legacy,Static,Predictable,Inherit
There are several other features are also there like following
Live Data Binding
Observer pattern using JavaScript and JavaScript objects
ADONetServiceProxy Class
Formview Control Ehancements
Ajax Improvements in asp.net 4.0
I have just list some of the features you can have all the features available in asp.net 4.0 white paper from the following link.
http://www.asp.net/learn/whitepapers/aspnet40/
Cheers… Happy Programming…
Before some time a reader vamsi asked me in my increase asp.net application performance post that why should i prefer data reader over dataset. Both data reader and dataset are usually use to fetch data from the database but both are having different mechanism for fetching data from database. First we looked into that and then we decide in which condition we need to use dataset and in which condition we need to use data reader.
DataReader:
Datareader fetch data one by one from the database. You can have one row(record) at a time in datareader. Once you read next row with read method of the datareader the older record is destroyed from memory and new record will take place instead of it. You can do that only forward only and you can not modify the data. It also require a database connection to stayed open while fetching data. You can use CommandBehavior.CloseConnection property to close connection after data reader finish reading data from database.
Dataset:
You can call dataset a mini database in your memory. Dataset support disconnected architecture as once you fill dataset with data then no connection is required. A database can contain multiple tables also its supports relationship between them. You can insert,update and delete records from dataset and you can update them also in database.
Where i should use dataset over database?
When you are required to display only data then use datareader.Dataset will fetch data once a time. So if you are having millions of records then it will consume your server memory while datareader will have just one record at a time in database. And you need not to display millions of records at time.
Following are the link from which you can find which is best suited for your need.
http://www.simple-talk.com/dotnet/.net-framework/should-you-use-ado.net-datareader-or-dataset/
http://aspnet.4guysfromrolla.com/articles/050405-1.aspx
http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic740.aspx