Solved

enum in C#

Posted on 2007-11-27
5
1,633 Views
Last Modified: 2008-02-01
This works in VB.Net but cant figure out what's wrong in C# with this. (new to C#).

1. I have a class like this in my DAL :
namespace Uni.DIAL.IDAL.Common {
 public sealed class DBTools
    {
       private static DataProvider _DBType;
        public static DataProvider DBType
        {
            get { return _DBType; }
            set { _DBType = value; }
        }
   
    }
}

2. In my Presenation layer I have:
class CheckPCALL
    {
        public enum DataProvider
        {
            SqlServer, OleDb, Odbc, IBM
        }
        static void Main(string[] args)
        {
           //Console.Write("Hello");
                Uni.DIAL.IDAL.Common.DBTools.DBType =  DataProvider.SqlServer;
                      }
    } //end of class

*** I get the Cannot implicitly convert type 'Uni.DIAL.DispositionNumber.CheckPCALL.DataProvider' to 'DataProvider'. An explicit conversion exists (are you missing a cast?)

*** I found http://www.csharp-station.com/Tutorials/Lesson17.aspx and added an int to it but no.

How can I fix this??
0
Comment
Question by:Camillia
5 Comments
 
LVL 7

Assisted Solution

by:Maverick_Cool
Maverick_Cool earned 100 total points
ID: 20359754
Uni.DIAL.IDAL.Common.DBTools.DBType = (Uni.DIAL.IDAL.Common.DBTools.DBType) DataProvider.SqlServer;


You need convert c# doesnot accept as variant as in vb or asp

May be you define custom enum  if required
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 400 total points
ID: 20359782
you have define DataProvider enum twice, somewhere.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20359939
eh, i did have it defined somewhere else. I was copying from VB.Net and pasting to C#. Got an error , and copied the enum somewhere else and forgot to take that one out...

but is Maverick correct? I have "Uni.DIAL.IDAL" at the top of the class...so maybe that's why DataProvider.SQLServer works without specifying the class?
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20360228
If the type of the DBType property is an enum, you should use one of the items from that enum.

If you create your own enum and cast to another enum, the value will be converted directly without matching the names of the enums. If the items of the enums are not specified in the exact same order, you will get the wrong value. Also, if the definition of either enum changes so that they don't match any more, you will not get any warning when compiling.
0
 
LVL 7

Author Comment

by:Camillia
ID: 20360233
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now