are conversion operators only applicable to numeric types .net

I was wondering whether overriding conversion operators is only applicable to numeric types? If not in what instances would the implicit or explicit conversion operator be applicable to other value types or reference types. An example would be great. Thanks

Answers


No - you can use any type.

For example, XAttribute has a range of conversions defined that make various conversions simple:

    XAttribute attrib = new XAttribute("Foo", "12345");
    int i = (int)attrib;
    string s = (string)attrib;

Another useful example is Jon's NonNullable<T> - this is intended to work neatly with classes while disallowing nulls. The conversion operators make it easy to use.


Need Your Help

which is better way to run a file system monitoring service?

python linux filesystemwatcher inotify

I need to monitor NAS file system disk space, whenever file-system disk space goes above from a threshold value, I am I deleting oldest files from file system to bring back file system disk space b...

IE8 not displaying ONE image

html css internet-explorer internet-explorer-8

This is driving me crazy. I'm working on a site, every other browser displays this image, including IE6, 7 and 9. But in IE8 disregards this image completely. Does anyone have any idea what is g...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.