Find jobs | Company-wise jobs
Jobseekers | Employer login
About us Sitemap of www.CareerRide.com Sitemap FAQ related with www.CareerRide.com FAQ Click here to Contact us Contact
       
Submit Resume Free ! | Access Resume Free !
Home Career services Resume services Interview Q&A Articles Oracle SQL Server NET Java Soft Skills CV GD Work from home Books store
Interview questions
ASP.NET | ADO.NET | AJAX
C#.NET | VB.NET | PHP
NET Remoting | NET Interview
  
C | C++ | Java | Oops
Data Structure | OS
   
Database concepts | Oracle
SQL Server | Biztalk | Sharepoint
Notification services
Reporting Services
Service-oriented architecture
Data warehousing | MySQL
  
Project Management 
Linux | Testing | Networking
Software engineering 
Microsoft solution framework 
  
UML | XML | HTML | SOAP 
CSS | VBScript  | Web Services
   
CV Cover letter | Interview 
HR | Soft skills | GD 
Working from Home 
Share your knowledge 
Tutorial
ASP.NET | VB.NET | C#.NET     
Remoting.NET | Web service
Remoting overview | ADO.NET
UML | Sql server 

Anonymous types


Understanding Anonymous Types

Anonymous types defined with var are not VB variants. The var keyword signals the compiler to emit a strong type based on the value of the operator on the right side. Anonymous types can be used to initialize simple types like integers and strings but detract modestly from clarity and add little value. Where var adds punch is by initializing composite types on the fly, such as those returned from LINQ queries. When such an anonymous type is defined, the compiler emits an immutable—read-only properties—class referred to as a projection.

Anonymous types support IntelliSense, but the class should not be referred to in code, just the members.

The following list includes some basic rules for using anonymous types:
  • Anonymous types must always have an initial assignment and it can’t be null because the type is inferred and fixed to the initializer.
  • Anonymous types can be used with simple or complex types but add little value to simple type definitions.
  • Composite anonymous types require member declarators; for example, var joe = new {Name=”Joe” [, declaratory=value, ...]}. (In the example, Name is the member declaratory.)
  • Anonymous types support IntelliSense.
  • Anonymous types cannot be used for a class field.
  • Anonymous types can be used as initializers in for loops.
  • The new keyword can be used and has to be used for array initializers.
  • Anonymous types can be used with arrays.
  • Anonymous types are all derived from the Object type.
  • Anonymous types can be returned from methods but must be cast to object, which defeats the purpose of strong typing.

Anonymous types can be initialized to include methods, but these might only be of interest to linguists.

The single greatest value and the necessity of anonymous types is they support creating single-use elements and composite types returned by LINQ queries without the need for the programmer to fully define these types in static code. That is, the designers can focus significantly on primary domain types, and the programmers can still create single-use anonymous types ad hoc, letting the compiler write the class definition. Finally, because anonymous types are immutable—think no property setters—two separately defined anonymous types with the same field values are considered equal.

Click here to read the complete chapter

 
  Book Excerpt: LINQ Unleashed for C#

Reproduced from the book LINQ Unleashed for C#. Copyrightã 2008, Pearson Education, Inc., 800 East 96th Street, Indianapolis, IN 46240.

Click here to read the complete chapter with following topics:
  • Programming with Anonymous Types

  • Databinding Anonymous Types

  • Testing Anonymous Type Equality

  • Using Anonymous Types with LINQ Queries

  • Introducing Generic Anonymous Methods



More Related Links

Essential LINQ

Essential LINQ is the first LINQ book written by leading members of Microsoft's LINQ and C# teams. Writing for architects, developers, and development managers, these Microsoft insiders share their intimate understanding of LINQ, revealing new patterns and best practices for getting the most out of it. Calvert and Kulkarni begin by clearly explaining how LINQ resolves the long-time "impedance mismatch" between object-oriented code and relational databases. Next, they show how LINQ integrates querying into C# as a "first-class citizen." Using realistic code examples, they show how LINQ provides a strongly typed, IntelliSense-aware technology for working with data from any source, including SQL databases, XML files, and generic data structures.

.Net Framework 

This includes introduction of .Net framework, .Net framework architecture, role of assembly and GAC.

.NET Code Security

This includes explanation of code security, Principal object, declarative and imperative security, role-based security, code access security and code group.

.NET Assembly 

This article explains .Net assembly, private and shared assembly, satellite assemblies, resource-only assembly, ResourceManager class, strong name, global assembly cache.

Understanding AJAX

AJAX is an acronym for Asynchronous JavaScript and XML. If you think it doesn't say much, we agree. Simply put, AJAX can be read "empowered JavaScript", because it essentially offers a technique for client-side JavaScript to make background server calls and retrieve additional data as needed, updating certain portions of the page without causing full page reloads.............

AJAX Benefits

AJAX offers benefits to both end users and developers. For end users, it reduces the “rich or reach” conflict; for developers, it helps in overcoming the constraints raised by HTTP.............

What Is ASP.NET AJAX?

ASP.NET AJAX is the name of Microsoft’s AJAX solution, and it refers to a set of client and server technologies that focus on improving web development with Visual Studio. Other companies have their own AJAX solution, often taking a radically different approach..........

AJAX Libraries

In addition to ASP.NET AJAX, many third-party AJAX libraries are available that can be used with ASP.NET, although not all of them were specifically designed for it. Some are mostly focused on providing JavaScript libraries for use from within the browser to make manipulation of the browser DOM (Document Object Model) easier..................

 

More content
Java FAQ | Personal Interview
Earn promotion|Happy employee
Write a good CV | Cover Letter
Become boss's favorite | CV tips
Training and Development
Public relations
PM | CareerRide is hiring
Frequently Asked Questions
CV Writing
Testing
XML
.NET
AJAX
ASP.NET
VB.NET
C#.NET
NET Framework
OOPS in .NET
C++
Data warehousing
Sql Server
Core Java
JDBC
JMS
JSP
RMI
J2ME
EJB
MySQL
Linux
PHP
UML
ADO.NET
Net Architecture
Personal interview
Marketing
Mass communication
Java FAQs
Oracle FAQs
C#.NET FAQs
VB.NET FAQs
DOT.NET
Networking FAQs
MySQL FAQs
Copyright © 2008 - 2010 CareerRide.com. All rights reserved.