Solved

enum in C#

Posted on 2007-11-27
5
1,639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.

734 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