Is it possible in .NET 2.0 extend built in types using partial classes?

  • Thread starter Thread starter The Crow
  • Start date Start date
T

The Crow

for example can we write a partial public class String {} and add some
static/instance methods to String class of .Net 2.0 framework?
 
for example can we write a partial public class String {} and add some
static/instance methods to String class of .Net 2.0 framework?

No, partial classes are merged at compile time. You can't add
functionality to existing compiled types.


Mattias
 
for example can we write a partial public class String {} and add some
static/instance methods to String class of .Net 2.0 framework?

No. Partial classes allow you to split up classes at *compile* time -
all the pieces have to present at the same time.

Extension methods in C# 3.0 will allow you to do something which
*appears* to be adding members to the String class (but is actually
just calling static methods in your own class).
 
You will not have this type of functionality until the Orcas build of Visual
Studio and the .NET Framework (next year?). C# 3.0 adds extension methods.
Technically, you are not extending the actual class, but that is how it
appears when you use them.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top