Skip to main content

Posts

Showing posts with the label LINQ

Quick Examples for LINQ Select And SelectMany and Differences

What is the Difference Between LINQ Select and SelectMany Say we are having a Customer class and Order class     class Customer     {         public string CusotmerName { get ; set ; }         public string CusotmerCode { get ; set ; }         public string CusotmerStatus { get ; set ; }         public List < Order > OrderList { get ; set ; }           public Customer( string pCusotmerName, string pCusotmerCode, string pCusotmerStatus, List < Order > pOrderList)         {             CusotmerName = pCusotmerName;             CusotmerCode = pCusotmerCode;             CusotmerStatus = pCusotmerStatus;             OrderList = pOrderList;         }     }         class Order     {         public int OrderNumber { get ; set ; }         public DateTime OrderDate { get ; set ; }         public string OrderStatus { get ; set ; }           public Order( int pOrderNumber, DateTime pOrderDate, string pOrderStatu

Generate CSV values easily in C# , String Manipulation in C#

Suppose you are having a List<String> and you are in need to generate a Comma Separated Value (CSV) from this with single quotes attached   Say We need to dynamically generate a simple SQL Select statement from a Order table and the filter criteria would be like this   Select New ('NO') Orders, Active ('AO') Orders and Successful ('SO') Orders Let's we have a Status Codes in a List<String>   The desired output SELECT * FROM ORDERS WHERE STATUS IN ('NO', 'AO', 'SO')   Traditional Solution   TraditionalSolution(StatusCodes);   private static void TraditionalSolution( List < string > StatusCodes) { // Traditionally what we will do is // Loop through the List and generate a SQL Statement   string OutputSQL = "SELECT * FROM ORDERS WHERE STATUS IN (" ;   int Count = StatusCodes.Count(); foreach ( string SingleStatusCode in StatusCodes) { OutputSQL += "