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

Enum Property with Interface

What do I to declare the header of a Property in an Interface, and should this property return a generic Enum?

Example:

public interface IMetric
{
Enum Unit { get;}
}

public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}

private EnumTeste _Unit;

public EnumTeste Unit
{
get
{
return _Unit;
}
}
}
Aug 17 '06 #1
2 20107
Cristiano de Pádua Milagres Oliveira wrote:
What do I to declare the header of a Property in an Interface, and
should this property return a generic Enum?

Example:
public interface IMetric
{
Enum Unit { get;}
}

public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTeste _Unit;
public EnumTeste Unit
{
get
{
return _Unit;
}
}
}
This compiles and works:

public interface IMetric
{
Enum Unit { get;}
}
public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public Enum Unit{ get{ return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumTest ttt = (ClassTest.EnumTest)tt.Unit;
}
}

Or using generics:

public interface IMetric<T>
{
T Unit { get;}
}
public class ClassTest : IMetric<ClassTest.EnumTest>
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public EnumTest Unit { get { return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumTest ttt = tt.Unit;
}
}

Aug 17 '06 #2
Thanks, the change was small but the help was large!

"Andreas Mueller" <me@privacy.netescreveu na mensagem
news:4k************@individual.net...
Cristiano de Pádua Milagres Oliveira wrote:
>What do I to declare the header of a Property in an Interface, and should
this property return a generic Enum?

Example:
public interface IMetric
{
Enum Unit { get;}
}

public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTeste _Unit;
public EnumTeste Unit
{
get
{
return _Unit;
}
}
}

This compiles and works:

public interface IMetric
{
Enum Unit { get;}
}
public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public Enum Unit{ get{ return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumTest ttt = (ClassTest.EnumTest)tt.Unit;
}
}

Or using generics:

public interface IMetric<T>
{
T Unit { get;}
}
public class ClassTest : IMetric<ClassTest.EnumTest>
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public EnumTest Unit { get { return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumTest ttt = tt.Unit;
}
}

Aug 17 '06 #3

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

Similar topics

0
by: Kakaiya | last post by:
UCTest.vb ---------- Imports System.ComponentModel Public Class UCTest Inherits System.Windows.Forms.UserControl #Region " Windows Form Designer generated code "
2
by: Kimmo Laine | last post by:
Hello, is there a way to do this VB6 code in C#: Enum MyEnumA A1 A2 End Enum Enum MyEnumB
6
by: Bob | last post by:
It should be simple, but I'm stuck on this one... how do you return a value for an enum property type? TIA, Bob
1
by: Jenny Fletcher | last post by:
I am trying to dynamically invoke a property of enumeration type but I can't find a way to get it to work. This is my code which works fine until I call InvokeMember and I get an ArgumentException....
2
by: Lance | last post by:
Can somebody tell me how to allow the user to check and uncheck Enum flags in a PropertyGrid. In other words, how to display a drop down box that contains a check next to each enum value as well as...
3
by: Frank | last post by:
Hello, question about the values for a property. I have a class with an enum and property: classA public enum x as short a b c end enum
3
by: Alan | last post by:
Hi, is it possible to create a project that can offer different members of a Public Enum according to a condition ? I mean, Project A has a public enum. Project B & C access A's enum. However B...
2
by: fred | last post by:
Hi, Why should I do a cast (IOfferSetter) in the constructor of the Test class? Thanks. Fred public interface IOfferSetter { object Offer { set;} } public class OfferCtx {
3
by: Andrew Bainbridge | last post by:
Hi, I'm converting some code over from vb.net to c# and have the following issue. In VB you can have enum's within an interface. i.e. Public Interface Class1 Enum ColorType Black Red
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.