enumeration

Enumerator Implementation: Use struct or class?

会有一股神秘感。 提交于 2020-01-01 08:28:28
问题 I noticed that List<T> defines its enumerator as a struct , while ArrayList defines its enumerator as a class . What's the difference? If I am to write an enumerator for my class, which one would be preferable? EDIT: My requirements cannot be fulfilled using yield , so I'm implementing an enumerator of my own. That said, I wonder whether it would be better to follow the lines of List<T> and implement it as a struct. 回答1: Like this others, I would choose a class. Mutable structs are nasty.

Possible multiple enumeration of IEnumerable? [duplicate]

♀尐吖头ヾ 提交于 2019-12-31 10:40:14
问题 This question already has answers here : Handling warning for possible multiple enumeration of IEnumerable (7 answers) Closed 5 years ago . why is that ? how can I fix it ? 回答1: There is nothing to fix here. Any() will iterate the enumeration but stop after the first element (after which it returns true). Multiple enumerations are mainly a problem in two cases: Performance: Generally you want to avoid multiple iterations if you can, because it is slower. This does not apply here since Any()

XSLT: Get enumeration from xsd

人盡茶涼 提交于 2019-12-31 03:52:05
问题 I've this enum in the xsd file: <xs:simpleType name="SO"> <xs:restriction base="xs:string"> <xs:enumeration value="Mac OS X"/> <xs:enumeration value="Windows Server"/> <xs:enumeration value="Windows Vista"/> <xs:enumeration value="Windows XP"/> <xs:enumeration value="Windows 7"/> <xs:enumeration value="Windows 8"/> <xs:enumeration value="Windows 8.1"/> <xs:enumeration value="Ubuntu"/> </xs:restriction> </xs:simpleType> and I need to get it in the XSL to use it in a javascript combobox. There

Java MyBatis Enum string value

你离开我真会死。 提交于 2019-12-30 09:06:38
问题 I feel like this is a simple problem, but none of the things i tried work for me. I have an enum, the reason i have string constructor is because Java doesn't allow enum to be numerical..I tried AA, AB, 2C directly without string constructor but that gives an error. Note that for the existing enum i am adding C("2C"). public enum TestEnum{ AA("AA"), AB("AB"), C("2C"); private String display; private TestEnum( String display ) { this.display = display; } public String toString() { return

Dictionary enumeration in C#

北慕城南 提交于 2019-12-30 01:40:09
问题 How do I enumerate a dictionary? Suppose I use foreach() for dictionay enumeration. I can't update a key/value pair inside foreach() . So I want some other method. 回答1: To enumerate a dictionary you either enumerate the values within it: Dictionary<int, string> dic; foreach(string s in dic.Values) { Console.WriteLine(s); } or the KeyValuePairs foreach(KeyValuePair<int, string> kvp in dic) { Console.WriteLine("Key : " + kvp.Key.ToString() + ", Value : " + kvp.Value); } or the keys foreach(int

In java, What does such enum type compile to?

流过昼夜 提交于 2019-12-30 00:33:05
问题 Below is the code that defines enum type. enum Company{ EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25); private int value; private Company(int value){ super(this.name()); this.value = value; } public int getValue(){ return value; } } that gets internally compiled to, final class Company extends Enum<Company>{ public final static Company EBAY = new Company(30); public final static Company PAYPAL = new Company(10); public final static Company GOOGLE = new Company(15); public final static

IEnumerable<T> as return type

爱⌒轻易说出口 提交于 2019-12-28 02:49:07
问题 Is there a problem with using IEnumerable<T> as a return type? FxCop complains about returning List<T> (it advises returning Collection<T> instead). Well, I've always been guided by a rule "accept the least you can, but return the maximum." From this point of view, returning IEnumerable<T> is a bad thing, but what should I do when I want to use "lazy retrieval"? Also, the yield keyword is such a goodie. 回答1: This is really a two part question. 1) Is there inherently anything wrong with

Enumerations: Why? When?

家住魔仙堡 提交于 2019-12-28 02:04:49
问题 I am an almost-graduating computer science student, and throughout my coding career, I've found very few instances where enumerations, except for canonical cases such as representing the faces of a standard deck of cards, are used. Do you know of any clever ways that enums are used in everyday coding? Why are enumerations so important and in what situations should one be able to identify that building an enumeration is the best approach? 回答1: These are the main arguments for enum, EnumMap,

Case objects vs Enumerations in Scala

梦想的初衷 提交于 2019-12-27 09:02:19
问题 Are there any best-practice guidelines on when to use case classes (or case objects) vs extending Enumeration in Scala? They seem to offer some of the same benefits. 回答1: One big difference is that Enumeration s come with support for instantiating them from some name String. For example: object Currency extends Enumeration { val GBP = Value("GBP") val EUR = Value("EUR") //etc. } Then you can do: val ccy = Currency.withName("EUR") This is useful when wishing to persist enumerations (for

Equal spacing in Enumerations?

落花浮王杯 提交于 2019-12-25 03:13:44
问题 I was working on a Java lesson and the section was on Enumerations. I have this in my Enum: public enum tuna { Camaro("Orange", "1968"), Silverado("Red","1996"), Sierra("Black","2007"), Equinox("Silver","2011"); private final String color; private final String year; tuna(String carColor, String age){ color = carColor; year = age; } public String getColor(){ return color; } public String getYear(){ return year; } } and this in my Java Class that prints it out: for(tuna cars: tuna.values()){