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

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?
 
M

Mattias Sjögren

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
 
J

Jon Skeet [C# MVP]

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).
 
G

Guest

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!
***************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top