I have an enum like this:  public enum MyEnum {     people1,     people2 }   I want to override or overload ToString() method. For example in the following code, variable s becomes "This is people 1".  string s=MyEnum.people1.ToString(); //I want s to become "This is people 1"   I don't want to create another method with extension method, I want to override or overload ToString method.
I have the following enumeration:  public enum AuthenticationMethod {     FORMS = 1,     WINDOWSAUTHENTICATION = 2,     SINGLESIGNON = 3 }   The problem however is that I need the word "FORMS" when I ask for AuthenticationMethod.FORMS and not the id 1.  I have found the following solution for this problem ():  First I need to create a custom attribute called "StringValue":  public class StringValue : System.Attribute {     private readonly string _value;      public StringValue(string value)     {         _value = value;     }      public string Value     {         get { return _value; }     }  }   Then I can add this attribute to my enumerator:  public enum AuthenticationMethod {     [StringValue("FORMS")]     FORMS = 1,     [StringValue("WINDOWS")]     WINDOWSAUTHENTICATION = 2,     [StringValue("SSO")]     SINGLESIGNON = 3 }   And of course I need something to retrieve that StringValue:  public static class StringEnum {     public static string GetStringValue(Enum value)     {         string output = null;         Type type = value.GetType();          //Check first in our cached results...          //Look for our 'StringValueAttribute'           //in the field's custom attributes          FieldInfo fi = type.GetField(value.ToString());         StringValue[] attrs =            fi.GetCustomAttributes(typeof(StringValue),                                    false) as StringValue[];         if (attrs.Length &gt; 0)         {             output = attrs[0].Value;         }          return output;     } }   Good now I've got the tools to get a string value for an enumerator. I can then use it like this:  string valueOfAuthenticationMethod = StringEnum.GetStringValue(AuthenticationMethod.FORMS);   Okay now all of these work like a charm but I find it a whole lot of work. I was wondering if there is a better solution for this.  I also tried something with a dictionary and static properties but that wasn't better either.
Based on the question , I got curious. Is there a guide or resource that describes how the price of a ticket is determined?  When you search you often see curious effects like cheaper tickets for a flight from A to B with a layover compared to a direct flight. This seems counter-intuitive from an outsider's perspective since you fly twice. Also one way tickets more expensive than 2 ways.  It can be a short set of rules. Something that helps someone to get started with finding good prices. I know these can be very complex and they probably change over time and over airline interests but there is probably a simplified set of rules that can be enunciated. In the simple linear regression case $y=\beta_0+\beta_1x$, you can derive the least square estimator $\hat\beta_1=\frac{\sum(x_i-\bar x)(y_i-\bar y)}{\sum(x_i-\bar x)^2}$ such that you don't have to know $\hat\beta_0$ to estimate $\hat\beta_1$  Suppose I have $y=\beta_1x_1+\beta_2x_2$, how do I derive $\hat\beta_1$ without estimating $\hat\beta_2$? or is this not possible? One single command to update everything in Ubuntu? Extreme of $\cos A\cos B\cos C$ in a triangle without calculus. If $A,B,C$ are angles of a triangle, find the extreme value of $\cos A\cos B\cos C$.   I have tried using $A+B+C=\pi$, and applying all and any trig formulas, also AM-GM, but nothing  helps.  On this topic we learned also about Cauchy inequality, but I have no experience with it.  The answer according to Mathematica is when $A=B=C=60$.  Any ideas? Interpretation of mean absolute scaled error (MASE) How do I prevent new villager trades from spawning? When making a custom adventure map, usually you only want the trades you programmed into a villager to show up. By default, however, the game will try to spawn new trades when the last one is made. The classic way I'm seeing in tutorials to prevent new trades is to make the last trade untradeable; however, with the release of 1.7, a lot of the old item IDs that were unobtainable have been removed from the game altogether, and following the tutorial I have crashes the game when the trade interface is scrolled to the last trade.   So there's two parts to this question:   Is there a better way to prevent new trades with the 1.7 mechanics? Or with the snapshots of 1.8 mechanics? If not, what is a safe data ID to use to prevent the last trade from being a real trade as of 1.7? Let $f:\mathbb{R}\to \mathbb{R}$ be a continuous map such that $\overline{f(\mathbb{N})} = \mathbb{R}$. Prove that $f$ is surjective.  I tried to use the definition of the continuity and $\overline{f(\mathbb{N})} = \mathbb{R}$ to show that $f$ is surjective but it didn't work. Since $f$ is continuous, the preimage of every open set is open. Also it results in $f(\overline{A})\subseteq \overline{f(A)}$ for every set $A$. How this couples with $\overline{f(\mathbb{N})} = \mathbb{R}$ to show surjectivity? Dumbed-down explanation how scientists know the number of atoms in the universe? It is often quoted that the number of atoms in the universe is 10$^{70}$ or 10$^{80}$.  How do scientists determine this number?   And how accurate is it (how strong is the supporting evidences for it)?  Is it more likely (logically >50% chance) that the numbers are right, or is it more likely that the numbers are wrong? How can I programmatically delete a line from a Word document using c#? Change keyboard layout (English UK) on command line to English US What does dot-equals mean in Perl? I'm using Jabref to manage my Bibliography.  Sometimes, I put directly:     First Author et al.   when adding the article author's name in Jabref.  When compiling my .tex file, LaTeX doesn't recognize the et. al as more names. It takes it as a name/surname.  This is an example of a Bibliography entry in Jabref.  @ARTICLE{Wolf2003,     author = {Wolf, K.et al.},     title = {Compensation mechanism in tumor cell migration: mesenchymal–amoeboid     transition after blocking of pericellular proteolysis},     journal = {J. Cell Biol.},     year = {2003},     volume = {160},     pages = {267–277},    }   This is a .texMWE with the bib entry mentioned:  \documentclass[11pt]{book}   \usepackage{cite}   \bibliographystyle{unsrt} \begin{document}   Here is the bib entry mentioned\cite{Wolf2003}    \bibliography{bibfile}  \end{document}   Here's the output:   How can I solve this problem? Initialize parameter of method with default value After upgrading to Firefox 57 Quantum many website have rendering issues, such as empty frames, missing text or fonts, etc. I use Kubuntu 16.04 64 bit.  So far, I've tried:   Restarting Firefox in safe mode Disabling "hardware acceleration"   Wiping out my profile Purging Firefox and reinstalling Running Firefox from a clean user account   But nothing helped so far.  Any tips on how to solve this are much appreciated How can I share files over a Windows network? I have a media computer which I recently reformatted to Ubuntu 10.04. I am probably just missing something obvious but I can't figure out how to share folders and files, so that I can browse to them on my Windows computers in order to copy files to/from the computer.  How do I do this? What is true for a ring with exactly two right ideals I watch a lot of old movies, and I've noticed that American actors of the 1930s and 1940s often spoke in a quasi-generic-posh-British accent.  Katherine Hepburn's accent would be the perfect example. It seems exaggerated, and I imagine it was not common off the stage and screen. What was that? Was it just an accent or was it a dialect? Did real people actually speak that way? Best way to return multiple values from a function? The canonical way to return multiple values in languages that support it is often . Option: Using a tuple Consider this trivial example: def f(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return (y0, y1, y2)  However, this quickly gets problematic as the number of values returned increases. What if you want to return four or five values? Sure, you could keep tupling them, but it gets easy to forget which value is where. It's also rather ugly to unpack them wherever you want to receive them. Option: Using a dictionary The next logical step seems to be to introduce some sort of 'record notation'. In Python, the obvious way to do this is by means of a dict. Consider the following: def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return {'y0': y0, 'y1': y1 ,'y2': y2}  (Just to be clear, y0, y1, and y2 are just meant as abstract identifiers. As pointed out, in practice you'd use meaningful identifiers.) Now, we have a mechanism whereby we can project out a particular member of the returned object. For example, result['y0']  Option: Using a class However, there is another option. We could instead return a specialized structure. I've framed this in the context of Python, but I'm sure it applies to other languages as well. Indeed, if you were working in C this might very well be your only option. Here goes: class ReturnValue:   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return ReturnValue(y0, y1, y2)  In Python the previous two are perhaps very similar in terms of plumbing - after all { y0, y1, y2 } just end up being entries in the internal __dict__ of the ReturnValue. There is one additional feature provided by Python though for tiny objects, the __slots__ attribute. The class could be expressed as: class ReturnValue(object):   __slots__ = [&quot;y0&quot;, &quot;y1&quot;, &quot;y2&quot;]   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  From the :  The __slots__ declaration takes a sequence of instance variables and reserves just enough space in each instance to hold a value for each variable. Space is saved because __dict__ is not created for each instance.  Option: Using a  (Python 3.7+) Using Python 3.7's new dataclasses, return a class with automatically added special methods, typing and other useful tools: @dataclass class Returnvalue:     y0: int     y1: float     y3: int  def total_cost(x):     y0 = x + 1     y1 = x * 3     y2 = y0 ** y3     return ReturnValue(y0, y1, y2)  Option: Using a list Another suggestion which I'd overlooked comes from Bill the Lizard: def h(x):   result = [x + 1]   result.append(x * 3)   result.append(y0 ** y3)   return result  This is my least favorite method though. I suppose I'm tainted by exposure to Haskell, but the idea of mixed-type lists has always felt uncomfortable to me. In this particular example the list is -not- mixed type, but it conceivably could be. A list used in this way really doesn't gain anything with respect to the tuple as far as I can tell. The only real difference between lists and tuples in Python is that lists are , whereas tuples are not. I personally tend to carry over the conventions from functional programming: use lists for any number of elements of the same type, and tuples for a fixed number of elements of predetermined types. Question After the lengthy preamble, comes the inevitable question. Which method (do you think) is best? Scala final vs val for concurrency visibility How can I disable the button of my CD/DVD drive? Up until Fedora 14 I was successfully using  to enable/disable the CD/DVD eject button on my laptop (Thinkpad T410). Sadly it has stopped working now.  I've consulted the methods discussed in these 2 questions:       None of which have worked for me. So I turn back to cdctl to see if we can't fix what's broken with it, since it's worked for so long.  Debugging the issue  So starting with cdctl switches I notice that most things seem to work just fine.  Examples  These things work.  ejects the drive  $ cdctl -e   list capabilities  $ cdctl -k Tray close             : 1 Tray open              : 1 Can disable eject      : 1 Selectable spin speed  : 1 Is a jukebox           : 0 Is multisession capable: 1 Can read the MCN (UPC) : 1 Can report media change: 1 Can play audio discs   : 1 Can do a hard reset    : 1 Can report drive status: 1   According to that list cdctl even thinks that it can enable/disable the eject button.   Can disable eject      : 1    So I continue on with debugging the issue.  Debugging cdctl  So I figure lets do an strace on cdctl to see if it can shed some light on what's going on.  $ strace cdctl -o1 ... brk(0)                                  = 0x1371000 open("/dev/cdrom", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory) open("/dev/cd", O_RDONLY|O_NONBLOCK)    = -1 ENOENT (No such file or directory) open("/dev/scd0", O_RDONLY|O_NONBLOCK)  = -1 ENOENT (No such file or directory) open("/dev/sr0", O_RDONLY|O_NONBLOCK)   = 3 ioctl(3, CDROM_LOCKDOOR, 0x1)           = 0 close(3)                                = 0 exit_group(0)                           = ? +++ exited with 0 +++   Curiously it seems like cdctl thinks it's disabling the button.   $ strace cdctl -o1 ioctl(3, CDROM_LOCKDOOR, 0x1)           = 0  $ strace cdctl -o0 ioctl(3, CDROM_LOCKDOOR, 0)             = 0   NOTE: If I understand this right, the return of a 0 means it was successful.  One thing that caught my eye here was the list of devices that cdctl is attempting to interact with. So I thought "what if I try these devices with eject"?  eject command  One of the other commands I used to use years ago was the eject command to interact with the CD/DVD device. I noticed that this command also now has a similar named switch:  $ eject --help  -i, --manualeject &lt;on|off&gt;  toggle manual eject protection on/off   Example  $ eject -i 1 /dev/sr0 eject: CD-Drive may NOT be ejected with device button  $ eject -i 0 /dev/sr0 eject: CD-Drive may be ejected with device button   So eject too thinks that it's disabling the button, yet it isn't either. Using strace here I see the same system calls:  $ strace eject -i 1 /dev/sr0 |&amp; grep ioctl ioctl(3, CDROM_LOCKDOOR, 0x1)           = 0  $ strace eject -i 0 /dev/sr0 |&amp; grep ioctl ioctl(3, CDROM_LOCKDOOR, 0)             = 0   So now I'm wondering if UDEV or something else is potentially blocking or taking ownership of device?  Thoughts?