Emailid
Password
         
  
    Forgot password

New user Sign Up
 

Partial Types and C#

       Current Rating:  0%                                                     Total Members Rated:  0
                                                                     Send To Friend

  

Partial Types and C#

 

 

Introduction

 

It is good object-oriented programming practice to maintain all source code for a type in a single file. Sometimes performance constraints force types to be large. The cost of splitting the type into subtypes is not acceptable for all situations. Programmers often create or use applications that emit source code, modifying the resulting code. But when source code is emitted again sometime in the future, all of the existing source code modifications are overwritten.

 

 

Partial Types

 

Partial types permits you to break up types consisting of a large amount of source code into several different source files for easier development and maintenance. Furthermore, partial types allow you to separate machine-generated and user-written parts of your types so that it is easier to supplement or modify code generated by a tool.

Here, two C# code files, File1.cs and File2.cs, both contain definitions for a class named Foo. Without partial types, this would represent a compiler error since both classes exist in the same namespace. With the partial keyword, we can indicate to the compiler that this class might have other definitions elsewhere.

 

File1.cs

public partial class Foo { public void MyFunction() { // do something here } }

 

File2.cs

 

public partial class Foo { public void MyOtherFunction() { // do something here } }

 

Upon compilation, the C# compiler gathers all definitions of a partial type and combines them. The resulting IL generated by the compiler shows a single combined class, rather than several component classes.

 

 

Standards agreement

 

C# programming language was ratified by the European Computer Manufacturer's Association (ECMA) as a standard (ECMA 334) in December 2001. Soon after, the C# standard was put on the "fast-track" process to the International Organization for Standards (ISO), where it is expected to be ratified shortly. A significant milestone in the evolution of a new programming language, the creation of a C# standard brought with it the promise of multiple implementations on a variety of operating system platforms. Indeed, as has been seen during its brief history, a number of third-party compiler vendors and researchers have implemented the standard and created their own versions of the C# compiler. With these proposed features, Microsoft invites customers to provide their feedback on their addition to the C# language and intends to submit these features to the ongoing standards process for the language. And it was practical.

 

 

All the best!


                           Rate This Article:   

Author is Offline
  Author: Raphaelin Mantein
       


Comments Posted
Label
Subject Author Status Date

 

Post Comment

Related Articles
Make your web site ‘perfect and Search Engine Friendly for Google and Yahoo
On making your content neat and tidy
Web site templates and its uses
Web Traffic and Higher Page Rank
How to increase visitors and traffic in your site



Home | About Us | Site Map | Privacy Policy | Submit Links