Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> LINQ >> I LINQ to Array.
I LINQ to Array.

Hi... In this blog I will show you that how to use LINQ for array.
Views: 2227     Comments: 4
by Awadhendra Tiwari on 8/12/2011

Hi...

In this blog I will give you a small demonstration on LINQ to ARRAY. Here I will explain you that how to use LINQ for array to perform certain task such as sorting of array and searching records from array. Here I had created two methods in Program class named displayValueInOrder() which accept two parameters, one string type array which needs to be sorted and other one is string value which is either ASC or DESC. Second method is searchSingleRecord() which search a record from array and also accept two parameters one is string array on which searching needs to be perform and second one is searchVale which needs to be search.

Here is simple program which clear your concept about LINQ to array.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqDemo
{
    class Program
    {
      
        /// <summary>
        /// This method display string array records either in ascending order
        /// or descending order on basis of order parameter. For performing
        /// this task I have use LINQ. We use orderby clause to specify ordering
        /// followed by variable name then order which is either ascending or
        /// descending. If you do not specify order then linq generate list
        /// in ascending order.
        /// </summary>
        public void displayValueInOrder(string[] records, string order)
        {
            if (order.Equals("ASC"))
            {
                var record = from std in records
                       orderby std ascending
                       select std;

                //Displaying record in ascending order.
                foreach (string data in record)
                    Console.WriteLine(data);
            }
            else
            {
                var record = from std in records
                       orderby std descending
                       select std;

                //Displaying record in descending order.
                foreach (string data in record)
                    Console.WriteLine(data);
            }
        }

        /// <summary>
        /// This method search record from array and display first search value.
        /// searchSingleRecord() method takes two parameter first records array
        /// in which search operation needs to be perform and second one is
        /// search value which needs to be searched. After searching record
        /// it display first value if exists from search record.
        /// </summary>
        public void searchSingleRecord(string[] records,string searchValue)
        {
            string record = (from std in records
                             where std.Equals(searchValue)
                             select std).FirstOrDefault();

            Console.WriteLine(record);
        }

        static void Main(string[] args)
        {
            string[] studentName = { "Awadhendra", "Ankit", "James", "John", "Cat", "Shilpa", "Shivam", "Haider", "Ashish" };

            Program pr = new Program();
            pr.displayValueInOrder(studentName, "ASC");

            Console.WriteLine();
            pr.searchSingleRecord(studentName, "Avanish");

            Console.ReadKey();
           
        }
    }
}

Thanks for reading this blog. Please provide any suggestion and feedback on this blog and suggest me some other topic in which I need to write articles or blogs.



how use datagridview control pop-up menu functions
by aken H on 9/8/2011

Hi  Awadhendra Tiwari ,

 Please provide about  how use datagridview control pop-up menu functions to  right key.

Thanks in advance.

Report Abuse

datagridview control pop-up menu functions
by Jenry Hock on 9/26/2011

Hi Aken,

Could you please explain your problem in more detail. What do you want to do with datagridview in this context.

Thanks.

Report Abuse

Linq to Array.
by James Smith on 10/3/2011
Thanks Awadhendra for this useful example.
Report Abuse

Linq to array.
by Rohit Kesharwani on 10/3/2011

Wow! Its really solve my problem............

 

Thanks Awadhendra.

Report Abuse
Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2679
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.