473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why can't the as operator perform user-defined conversions?

Why can't the as operator perform user-defined conversions?
Is it a C# problem or with MSIL? I can't see any reasons why the compiler
should'nt be able to use a user-defined conversion operator. Anyone knows the
answer?

http://msdn.microsoft.com/library/de...ml/vclrfas.asp

my c# blog: http://spaces.msn.com/members/pjsson/
Nov 16 '05 #1
1 1404
> Why can't the as operator perform user-defined conversions?

My guess it has to do with the resolution and chaining rules for implicit
and explicit conversion invocations.

The rules are actually different when you invoke a conversion explicitly
with a cast vs invoking it implicitly. Note that this is how the conversion
operator is *invoked*, not how it is *defined*. Explicit conversion operators
must be invoked explicitly while implicit operators can be used either way.

There would have to be more rules or syntax to distinguish the cases when
using the "as" operator. Perhaps they thought it was just more trouble than
it was worth?
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Roy Smith | last post by:
I've been running some benchmarks to compare streams and stdio performance. I've always suspected stdio was faster, but was astonished to discover how much faster. I timed the following running...
19
by: Eric Lilja | last post by:
Hello, I have a class that I want to be able to output detailed information about what it's doing either to a file or to the screen. What I first tried was adding a std::ostream-reference member...
11
by: lovecreatesbeauty | last post by:
Hello experts, Is const_cast only applied to pointers or references? If I have a constant object, then how can I remove constant attribute from it? #include <vector> #include <string>...
3
by: PengYu.UT | last post by:
I want to define a convolution operator for two Array objects. Unfortunately, * operator has been used for Array class. +,-,/ are not good candidates for convolution. Is there any other...
1
by: Sonu | last post by:
Hi All, How to use an IN operator using asp.net radio control list or checkbox list control For example... Select * from <table name> where name IN ('james','Bob','Jhon') how to use the...
15
by: angellian | last post by:
Sorry to raise a stupid question but I tried many methods which did work. how can I conserve the initial zero when I try to convert STR(06) into string in SQL statment? It always gives me 6...
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
5
by: hn.ft.pris | last post by:
Hi: I'm a beginer of STL, and I'm wondering why none of below works: ######################################################################## .......... string str("string"); if ( str == "s" )...
5
by: raan | last post by:
What I am trying to achieve here is depicted in the small program below. // Wrapit.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <map> #include...
1
by: ambanks04 | last post by:
ok I have to do the following to a previous program A) Modify the program loop such that a ‘SWITCH’ structure is used to call each of the FUNCTIONS which display the individual Logical Operator...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.