Solved

enum in C#

Posted on 2007-11-27
5
1,636 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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