My context is that I'm building a simple factory method for creating instances of derived types of a given base type.  The factory method only takes a type parameter, i.e. doesn't have any arguments.  This is obviously possible with an if-else if construct:  public Vehicle Create&lt;T&gt;() {     if (typeof(T) == typeof(Car))         return new Car(); // just an example; could be more complex logic.     else if (typeof(T) == typeof(Truck))         return new Truck(); // just an example; could be more complex logic.     else         throw new ArgumentException(             $"The type {typeof(T).Name} is not known by this method."); }   It's well-known by now how to use pattern matching in C# (as of C# 7.0) to branch based on the type of a variable but this doesn't work for a type parameter:  switch (T) { ... } // error: "'T' is a type, which is not valid in the given context"   or...  switch (typeof(T)) {     case Car c: ...      // err: "An expression of type 'Type' cannot be handled by a pattern of type 'Car'" }   So I'd like to know if it's possible to use switch to achieve the same result?    Research: I'm surprised this hasn't been asked before, but I can't find it.  I found  which has a name and a few answers that come pretty close but it's dealing with (numeric) value types and methods that have an argument of type T -- the generic type parameter.  Similarly,  also uses an argument.
Seeing as C# can't switch on a Type (which I gather wasn't added as a special case because is relationships mean that more than one distinct case might apply), is there a better way to simulate switching on type other than this?  void Foo(object o) {     if (o is A)     {         ((A)o).Hop();     }     else if (o is B)     {         ((B)o).Skip();     }     else     {         throw new ArgumentException("Unexpected type: " + o.GetType());     } }
Installing "firmware-b43-installer" offline How can I install firmware-b43-installer driver if I can't connect to internet by wire? For the following pretty straightforward task: query a list of products from a DB and present it on a webpage, consider 2 setups:  Setup1: PHP script queries. All content is built on the server and the entire page is served back to the client.  Setup2: Static HTML "page skeleton" requesting content using AJAX. Received content is parsed on the client side using Javascript and rendered using innerHTML or similar.  Of course the second setup only makes sense when you have pages, categories and tags for the client user to choose from.  I need to compare these two, at least by means of:   time it will take content to be served user experience (setup1 is delivered as a whole, setup2 is delivered in "two parts") scalability - how do the setups compare when I have 100,000 queries daily   Any thoughts on the issue will be much appreciated. MySQL 5.5.16 allows anonymous connections Apparently, I can connect to MySQL (at least from my localhost) without having to provide any username or password. I can even put anything as username, as long as the password is empty. I have access to the information_schema and test databases. I can create tables. If I run SELECT USER() it returns the proper value randomstring@localhost, where the random string is whatever I used for username when I connected.  The mysql.user table contains root@localhost, root@127.0.0.1, @localhost and pma@localhost. I manually set encrypted passwords to all the records (UPDATE user SET password=...) and only root has any privileges, the other two records have "N" for all privileges. That record with the empty username looks suspicious, but I don't think it has anything to do with this and I think it was there from the beginning.  To make matters worse, if I add a user with a password, I can only connect using empty string as password (just like if I put anything as username). If I try to connect using the username I created and password I supplied when creating it (CREATE USER .. IDENTIFIED BY ..) it doesn't work.  Does anyone know what is wrong and how I can fix this?  Note: I am using MySQL 5.5.16 for Windows, provided by the XAMPP package. How are "needs to be washed," "needs washing," and the regional variant "needs washed" to be distinguished"? I'm from Central Pennsylvania, and apparently, we have a strange language construct in this area. I was recently talking about how "my car needs washed" to a friend from NJ, and she told me that my sentence was grammatically incorrect.   I realize she's right, and I realize my options are "my car needs to be washed" or "my car needs washing". But I'm not clear on the precise rule being invoked. I recently installed Ubuntu 14.04, then I installed lamp-server and placed my webpages in /var/www directory, but when I opened localhost in the browser there was nothing. I think that happened because Zend updated Apache.  Whatever the reason may be, I want to know where to keep my php files so that I can access them from my browser. How to get all possible combinations of a list’s elements? I know there a lot of posts about ram but I'm still confused about it. I'm building a new system and because it was cheaper, I bought a 6GB kit from Corsair. So I'm wondering if I would be better off just using 4GB of it in a dual channel configuration or just add all 6GB (3 DIMMS) in a single channel configuration.   Thanks When an account is deleted, don't auto delete its negatively scored posts on the meta site Meta is different. Negatively scored questions are not always bad questions, and sometimes they have merit and draw good answers, especially discussions.  When an account (in the main site) is deleted, either by self deletion or by a moderator, all questions with score of -1 or less are being deleted regardless of their answers, both in the main and meta site.  Can you please change this behavior so that the questions on the per-site meta will survive and won't be auto-deleted? I am working on a Drupal mulsite project (using single database) and using Google Analytics module for this.  I have follow the below steps for GA configuration:   Created a domain name example1.com and a sub-domain name example2.com. Create an account on GA and create property for both of this domain name in GA account. Both property give me two different Tracking ID (same as below screenshot).      Into the configuration setting of GA from drupal admin section I have added Web Property ID of example1.com and into domain setting added both the domain name example1.com and example2.com into the section of List of top-level domains (a same as attached screenshot).      Now this configuration is only working for emample1.com, not for example2.com. So can anyone please tell me how can I use Web Property ID of domain exmaple2.php to get the result? How do I know if a given food or ingredient I have is still good, or if I should discard it?  How can I best preserve a food or ingredient?     This broad question is intended as a "general reference" question to quickly answer many how long will food keep for? questions. Please feel free to edit this question to expand and clarify as needed. Local BLAST Copy Number per Hit I generated a series of local BLAST databases using makeblastdb of metagenomic data and am searching for the presence of a particular gene. While I can do the normal BLAST analysis looking at e-values, % identity, etc. I haven't been able to figure out how to determine how many times a given sequence exists in the database.  So: given a BLAST database of metagenomic data where a particular gene may exist multiple times, how do I determine the copy number of a given BLAST hit?  Thanks in advance. I accidentally clicked reject on the suggested edit on this question(). I can't find the button to change it to Approve? In Xubuntu 16.04.3 (and several previous versions aswell) it is not possible to have no power icon in the notification area.  A power icon is displayed even though 'Show system tray icon' is unchecked in Xfce Power Manager.  When 'Show system tray icon' is checked, there are two power icons displayed.  (See screenshots)  I've searched and I can't find any information related to this in Xubuntu/Xfce.  Is there a way to fix or work around this bug? Adjective Used as an Adverb? That cake looks good.    In formal proper grammar, may good (adjective) get used as an adverb? Or, may you read it as, That cake (noun phrase, nominal[?], argument[?]), looks (verb, predicate[?]), good (subject compliment[?].? How may I discern this, grammatically? I know this sounds kind of ridiculous, but someone stole my mouse from my cubicle.. I came to work in the morning and was about to give my mouse a little shove to wake up the monitor, but it wasn't there!  I'm trying to figure out when this happened. I'm running Windows 7 and it's a USB mouse. I checked the event logs, but there doesn't seem to be any logs that might tell me what I'm looking for.  Is there any place where USB unplug events are logged? If a batsman hits the ball inside the ground and begins running between the wickets and now the ball is thrown back to the Fielder/Bowler/WK(FBWK)    If the FBWK catches the ball in one hand and hits the stumps with other hand before the batsman gets reached, is this a run out? If the FBWK catches the ball in hands and hits the stumps with leg or any other part of his body before the batsman gets reached, is this a run out?   This scenario can occur, when the ball was thrown far away from stumps. Java - Screen turns black, when setting a JFrame to Fullscreen Why is an orthogonal matrix called orthogonal? Proving that $x_n\to L$ implies $|x_n|\to |L|$, and what about the converse? Problem 3. Show that for a sequence $(x_n)$ the following are true:   (i) $\lim x_n=0$ if and only if $\lim |x_n|=0$.   (ii) $\lim x_n=L$ implies $\lim |x_n|=|L|$. Is the converse true? Prove or give a counterexample.    (i) is already done, easy.  I'm halfway done with (ii), I split it into three cases:  $L = 0$, $L &gt; 0$ and $L &lt; 0$.  For $L = 0$ I just refer to part (i).  For $L &gt; 0$, we know that $|x_n - L| &lt; \epsilon$   if lim $|x_n|$ = $|L|$, then we must have  $||x_n| -|L|| &lt; \epsilon$  but by the reverse triangle equality, $||x_n| - |L|| &lt; |x_n - L|$ so clearly $||x_n|-|L|| &lt; \epsilon$, thus  lim $x_n = L$ $\implies$ lim $|x_n| = |L|$ for $L &gt; 0$  for some reason I'm confused as to part three, $L&lt;0$. I'm having trouble seeing the difference between $L&gt;0$ and $L&lt;0$, and i'm starting to think that splitting it up like that isn't necessary at all. How to remove/apply all modifiers of one object in python Lets assume you have 1 object with 4 modifiers added to it. I am curious how one would approach the task to apply all or to delete all modifiers of a just selected object that has many modifiers already added.  The console reads out the modifier delete as  bpy.ops.object.modifier_remove(modifier="Box Right ")   So "Box Right " I might have to replace with something like active.object.modifier.name and then work each modifier off?  This would be very helpful when you want to generate a static mesh for animation or 3D printing.