?
Solved

enum in C#

Posted on 2007-11-27
5
Medium Priority
?
1,654 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 400 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 1600 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 to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

757 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