Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Working with Queries and Anonymous Types

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 287
    Comment on it
    1. Anonymous types is used to create new type without defining a type first
    2. It is used in LINQ, Returns a few of read only properties while querying collection of object using LINQ
    3. Use new keyword to define anonymous type
    4. It is reference type, derived from system.object
    5. If more than one anonymous types have same properties, and same order in same assembly then they consider us same type by the compiler.
    Example:
    
    Define anonymous type using new keword
    var Offer= new {offerid=100, Offername="50% discount on all famous brands"}
    
    returns set of few read only properties
    
    var OfferQuery = 
        from Offer in Offers
        select new 
        { 
        Offer.OfferName,
        Offer.discount
        };
    
    foreach (var Offerinfo in OfferQuery)
    {
        Console.WriteLine("OfferName={0}, Discount={1}", Offerinfo.OfferName, Offerinfo.discount);
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: