Create struct for Collection with new syntax : var « LINQ « C# / CSharp Tutorial





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


      public struct MyAddress
      {
         public String Name;
         public String Company;
         public String Address1;
         public String Address2;
         public String City;
         public String State;
         public String ZIP;
      }
public class MainClass{

   public static void Main(string[] args){   
         List<MyAddress> AddressCollection = new List<MyAddress>
         {
            new MyAddress{
               Name = "S",
               Address1 = "1234 ",
               Address2 = "3",
               City = "Anywhere",
               State = "WA",
               ZIP = "12345"
            },
            new MyAddress
            {
               Name = "M",
               Company = "Us",
               Address1 = "21st Street",
               City = "City",
               State = "MI",
               ZIP = "99999"
            }
         };

         foreach (MyAddress ThisAddress in AddressCollection){
            Console.WriteLine(
               ThisAddress.Name + "\r\n" +
               ThisAddress.Company + "\r\n" +
               ThisAddress.Address1 + "\r\n" +
               ThisAddress.Address2 + "\r\n" +
               ThisAddress.City + ", " +
               ThisAddress.State + "     " +
               ThisAddress.ZIP);
            
         }


   }
}










22.1.var
22.1.1.Using var
22.1.2.Anonymous Types
22.1.3.An Anonymous Type Assigned to a Variable Declared with the var Keyword
22.1.4.Instantiating and Initializing an Anonymous Type Using Object Initialization
22.1.5.An Example of Collection Initialization
22.1.6.Reflecting result from Linq
22.1.7.Explicit Range Variable
22.1.8.Automatic properties
22.1.9.Create struct for Collection with new syntax
22.1.10.Create and initialize the list of Simple type with new syntax
22.1.11.Filtering with OfType