473,388 Members | 1,277 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,388 software developers and data experts.

Compiler Error CS0117

Simplified code.

class A : object {
m() {}
}

class B : objet {
m() {}
}

class Test {
Test() {
object var = RANDOM ? new A() : new B();
var.m(); // Compiler Error CS0117
}
}

How can I get this functionality to work without a compiler
error (it works excellent in VB.Net).
Another example:

object db = RANDOM ? new SqlConnection() : new
OleDbConnection();
....
....
db.Open(); // Compiler Error CS0117

Jul 19 '05 #1
2 4163
Thomas Tryde <th**********@hotmail.com> wrote:
Simplified code.

class A : object {
m() {}
}

class B : objet {
m() {}
}

class Test {
Test() {
object var = RANDOM ? new A() : new B();
var.m(); // Compiler Error CS0117
}
}

How can I get this functionality to work without a compiler
error
Create a new interface which defines a method, and implement that
interface in both the classes you're interested in. Then do:

IWhatever var = RANDOM ? new A() : new B();
var.SomeMethod();
(it works excellent in VB.Net).


No, it probably works slowly using reflection, and it means that if you
have a typo in the method name, you won't know about it until you end
up running that code. Type safety is a good thing - use it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #2
It worked!
Thanks!
-----Original Message-----
Thomas Tryde <th**********@hotmail.com> wrote:
Simplified code.

class A : object {
m() {}
}

class B : objet {
m() {}
}

class Test {
Test() {
object var = RANDOM ? new A() : new B();
var.m(); // Compiler Error CS0117
}
}

How can I get this functionality to work without a compiler
error
Create a new interface which defines a method, and

implement thatinterface in both the classes you're interested in. Then do:

IWhatever var = RANDOM ? new A() : new B();
var.SomeMethod();
(it works excellent in VB.Net).
No, it probably works slowly using reflection, and it

means that if youhave a typo in the method name, you won't know about it until you endup running that code. Type safety is a good thing - use it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
.

Jul 19 '05 #3

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

Similar topics

1
by: Kerem Gümrükcü | last post by:
Hi, i get this error when i try to compile my code. But why, ...everything seems to be ok! When i try to get some files extension with this: "File Extension: " +...
3
by: Justin Dutoit | last post by:
Hey. I have the error CS0117 'BusinessLayer' does not contain a definition for 'MySoapHeader'. Below is a link to the asmx source, and the code which calls the web service. MS seems to do the same...
0
by: Justin Dutoit | last post by:
Hey. Take a look at this link. http://justindutoit.port5.com/QuickshopDocs/businesslayer.asmx.txt When I call the web service, I have the error CS0117 'BusinessLayer' does not contain a...
3
by: Nikhil Patel | last post by:
Hi all, I have a drop down in an asp.net form defined as below: <asp:DropDownList id="dropDownLeaseType" runat="server" OnSelectedIndexChanged="LeaseTypeChanged"></asp:DropDownList> I have...
1
by: manas | last post by:
hi, I am using showDialogModal to create a popup... the intial page is webform1.aspx and the popup page is error.aspx, I have the <base target="_self"> in webform1.aspx and the code i used is ...
2
by: Thomas Tryde | last post by:
Simplified code. class A : object { m() {} } class B : objet { m() {} }
1
by: Ashwani | last post by:
Hi, I am getting below error while using the ItemTemplate in datagrid. Please help, this is very very urgent. CS0117: 'System.Web.UI.DataBinder' does not contain a definition for 'eval' ...
4
by: B. | last post by:
Hi I have two projects, one written in MC++, and the other in C#. In MC++ header file, I have: namespace Domain { namespace Subdomain { namespace ManagedCPP { public class AClass
0
by: veera143 | last post by:
sir i'm using webservice in my project in that i've function like sel for fetch the data from database. that function was called by the button click event but the compilation error was happened in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.