Hi,
Say in the base class they have a vitual method that Gets Days.
Well, in the base class, only Monday through Friday are defined.
Now, I have to extend the days to include Saturday and Sunday. -
public BaseClass
-
{
-
public enum Days
-
{
-
Monday,
-
Tuesday,
-
Wednesday,
-
Thursday,
-
Friday,
-
}
-
public virtual Days_Enum GetDays(int i)
-
{
-
//Method to return enumerator i.e. return Days.Monday;
-
}
-
}
-
-
Class Parent : BaseClass
-
{
-
-
public override Days_Enum GetDays(int i)
-
{
-
//Method to return days, including weekend . i.e. Days.Saturday
-
}
-
}
-
TIA,
8 1872
Hi,
Say in the base class they have a vitual method that Gets Days.
Well, in the base class, only Monday through Friday are defined.
Now, I have to extend the days to include Saturday and Sunday.
<CODE>
public BaseClass
{
public enum Days
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
}
public virtual Days_Enum GetDays(int i)
{
//Method to return enumerator i.e. return Days.Monday;
}
}
Class Parent : BaseClass
{
public override Days_Enum GetDays(int i)
{
//Method to return days, including weekend . i.e. Days.Saturday
}
}
</CODE>
TIA,
So what have you done so far? What is the current implementation like and what conditions determine which day will be returned?
Here's an extract that should help you along ...
Straight from the C# language spec
Each enum type has a corresponding integral type called the underlying type of the enum type. An enum type that does not explicitly declare an underlying type has an underlying type of int. An enum type’s storage format and range of possible values are determined by its underlying type. The set of values that an enum type can take on is not limited by its enum members. In particular, any value of the underlying type of an enum can be cast to the enum type and is a distinct valid value of that enum type.
So what have you done so far? What is the current implementation like and what conditions determine which day will be returned?
Here's an extract that should help you along ...
Straight from the C# language spec
That is not important and irrelevant.
What is important is how to override the enumerator.
I did stumble upon using the 'new' keyword, but that doesn't seem to work properly. I even tried adding Parent.Weekday to no avail.
Here is some executable code that doesn't work. -
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
-
namespace Enum3
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
clsBaseClass First = new clsBaseClass();
-
clsNewClass Second = new clsNewClass();
-
First.ShowEnum(clsBaseClass.Weekdays.Fri);
-
Second.ShowEnum(clsNewClass.Weekdays.Fri);
-
}
-
-
public class clsBaseClass
-
{
-
// Define the enum type
-
public enum Weekdays
-
{
-
Sun, Mon, Tues, Wed, Thurs, Fri, Sat
-
}
-
-
public virtual void ShowEnum(Weekdays days)
-
{
-
Console.WriteLine("Day Value {0}", days.ToString());
-
}
-
-
}
-
class clsNewClass : clsBaseClass
-
{
-
public new enum Weekdays
-
{
-
Sun = 1, Mon, Tues, Wed, Thurs, Fri, Sat
-
}
-
public override void ShowEnum(Weekdays days)
-
{
-
Console.WriteLine("Day Value {0}", days.ToString());
-
}
-
}
-
}
-
}
-
Error 1 'Enum3.Program.clsNewClass.ShowEnum(Enum3.Program. clsNewClass.Weekdays)': no suitable method found to override C:\Documents and Settings\CSharpProgrammer\Local Settings\Application Data\Temporary Projects\Enum3\Program.cs 37 34 Enum3
Thanks,
That is not important and irrelevant.
....
The point I was trying to make is that values of the enumeration type are not restricted to the values of the named constants.
The point I was trying to make is that values of the enumeration type are not restricted to the values of the named constants.
Thanks, but I knew that.
I was just trying not really show too much detail and distract from the main content.
Oh well.
Thanks anyways,
EDIT:
ok I reproduced it.
The error is because your override function is incorrect.
To "override" a function, you need to use an identical declaration, which for the derrived class would be: -
public override void ShowEnum(clsBaseClass.Weekdays days)
-
{
-
//...
-
}
-
EDIT:
ok I reproduced it.
The error is because your override function is incorrect.
To "override" a function, you need to use an identical declaration, which for the derrived class would be: -
public override void ShowEnum(clsBaseClass.Weekdays days)
-
{
-
//...
-
}
-
Well, they are in fact identical. I guess it is must the signature that makes them different.
So, I suppose that means there is no way to override or add Enumerators without modifying the base class.
I wonder what would be a better way do that, without using numerators?
I just want to add more enumerators like Saturday and Sunday to an already existing Enumerator without having to modify the base class.
They are NOT identical.
In your code:
The base class signature is using the base class's enum.
The derived class signature is using the derived class's enum.
That is different.
Well, they are in fact identical. I guess it is must the signature that makes them different.
So, I suppose that means there is no way to override or add Enumerators without modifying the base class.
I wonder what would be a better way do that, without using numerators?
I just want to add more enumerators like Saturday and Sunday to an already existing Enumerator without having to modify the base class.
You cannot extend enums. You can inherit them from base classes however. If you inherit an enum from a base class you take it as it was. You can, however, use it differentlty in the inheriting class. i.e you can make it use values that are not being used in the base class(which is what was being explained in the specs above).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gordon Rundle |
last post by:
It drives me nuts that I can't use foreach with an enumerator
instance. I would like the following to be functionally identical:
foreach (Object o in MyCollection) ...
foreach (Object o in...
|
by: tony collier |
last post by:
if i have a string eg
string day="monday";
and an enumerator
enum days {monday=0,tuesday, wednesday}
|
by: Stephanie Stowe |
last post by:
Hi. I am trying to understand the weird System.DirectoryServices object
model. I have a DirectoryEntry object. I want to enumerate through the
PropertyCollection. So I looked at GetEnumerator....
|
by: rawCoder |
last post by:
Hi,
Which is better in terms of performance.
Iterating over Enumerator
ForNext loop (using indexer)
ForEach loop
Thanx
rawCoder
|
by: toldyouso |
last post by:
The following script works in IE but in Firefox errors with the msg
Enumerator is not defined.
<html>
<head>
<meta name="vs_defaultClientScript" content="JavaScript">
<script...
|
by: ajmastrean |
last post by:
I have a bunch of enumerators. I need to pass them into a function that
is designed to write all values of any enumerator to the console. For
instance...
public enum Days : int
{
Sunday = 1,...
|
by: csharpula csharp |
last post by:
Hello,
I have methods which refer to some class enumerator .Should I make it
pulic or encapsulate it?
*** Sent via Developersdex http://www.developersdex.com ***
|
by: Michael C |
last post by:
I'm reading about Iterators and the article I'm reading states that an
enumerator must load all of the objects into memory, which is obviously a
big waste if there are a large number of objects and...
|
by: Dave |
last post by:
I'm calling string.Split() producing output string. I need direct
access to its enumerator, but would greatly prefer an enumerator
strings and not object types (as my parsing is unsafe casting...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |