int[] testArray = new int[200000000];  Stopwatch st2 = new Stopwatch(); st2.Start();  for (var j = 0; j &lt; testArray.Length; j++) {  }  st2.Stop();  Console.WriteLine("Total milliseconds - FOR LOOP: {0}", st2.Elapsed.TotalSeconds);    Stopwatch st = new Stopwatch(); st.Start();  foreach (var arr in testArray) {  }  st.Stop();  Console.WriteLine("Total milliseconds - FOREACH LOOP: {0}", st.Elapsed.TotalSeconds);   Results:     for: 0,7046522 seconds   foreach: 0,05508682 seconds   Why is my foreach faster? I thought that my for loop would be faster than the foreach
In C#/VB.NET/.NET, which loop runs faster, for or foreach?  Ever since I read that a for loop works faster than a foreach loop a  I assumed it stood true for all collections, generic collections, all arrays, etc.  I scoured Google and found a few articles, but most of them are inconclusive (read comments on the articles) and open ended.  What would be ideal is to have each scenario listed and the best solution for the same.  For example (just an example of how it should be):   for iterating an array of 1000+ strings - for is better than foreach for iterating over IList (non generic) strings - foreach is better than for   A few references found on the web for the same:               [Edit]  Apart from the readability aspect of it, I am really interested in facts and figures. There are applications where the last mile of performance optimization squeezed do matter.
Reprojecting raster from 0 360 to -180 180 with cutting 180 meridian using gdalwarp I have a geotiff raster image that has a coordinate system with longitudes from 0 to 360. The horizontal center of the image is 180 longitude. See image below:    I want to transform it to EPSG:4326 SRS with -180 180 longtitude range.  And I want the center of the image to be at Greenwich meridian (0). I guess this srs is very widely used. I expect the result look like this:    So I use a gdalwarp command to reproject:  gdalwarp -s_srs '+proj=latlong +datum=WGS84 +pm=180dW' -t_srs EPSG:4326 test_col.tif test_4326.tif   But I only get a tiff with bigger dimensions (more pixels) and EPSG:4326 metadata. The image itself looks the same, as the initial one. But I expect it to swap the hemispheres.  How do I gdalwarp an image to be strictly -180 180 EPSG:4326 with the center in 0 longitude?  This is gdalinfo of my initial file:  Origin = (-0.102272598067084,89.946211604095552) Pixel Size = (0.204545196134167,-0.204423208191126) Metadata:   AREA_OR_POINT=Area Image Structure Metadata:   INTERLEAVE=BAND Corner Coordinates: Upper Left  (  -0.1022726,  89.9462116) (  0d 6' 8.18"W, 89d56'46.36"N) Lower Left  (  -0.1022726, -89.9462116) (  0d 6' 8.18"W, 89d56'46.36"S) Upper Right (     359.897,      89.946) (359d53'50.18"E, 89d56'46.36"N) Lower Right (     359.897,     -89.946) (359d53'50.18"E, 89d56'46.36"S) Center      ( 179.8975000,  -0.0000000) (179d53'51.00"E,  0d 0' 0.00"S)   This is gdalinfo after gdalwarp     Origin = (-180.102727401932952,89.946211604095552) Pixel Size = (0.091397622896436,-0.091420837939082) Metadata:   AREA_OR_POINT=Area Image Structure Metadata:   INTERLEAVE=PIXEL Corner Coordinates: Upper Left  (-180.1027274,  89.9462116) (180d 6' 9.82"W, 89d56'46.36"N) Lower Left  (-180.1027274, -89.9699975) (180d 6' 9.82"W, 89d58'11.99"S) Upper Right ( 179.8211116,  89.9462116) (179d49'16.00"E, 89d56'46.36"N) Lower Right ( 179.8211116, -89.9699975) (179d49'16.00"E, 89d58'11.99"S) Center      (  -0.1408079,  -0.0118929) (  0d 8'26.91"W,  0d 0'42.81"S) Explicitly accept change for PPA 'Label' When I run apt-get update on my ubuntu 17.10 I receive the following error:  E: Repository 'http://ppa.launchpad.net/ondrej/php/ubuntu artful InRelease' changed its 'Label' value from '***** The main PPA for PHP (5.6, 7.0, 7.1) with many PECL extensions *****' to '***** The main PPA for supported PHP versions with many PECL extensions *****' N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details."   The man page doesn't really point to a solution.  My question is, how do I explicitly accept the change? Are research survey questions expected to be handled with close votes? SINGLE_EMAIL_LIMIT_EXCEEDED. What does it mean? I got  question in review. First sentence is:     I know there is a  question, but no answers.   And indeed the two questions are virtually identical. I started to flag as duplicate - but the original question had no answer at the time, so it wouldn't be correct and apparently . (I didn't go so far as to try to submit the flag).  What is the proper action here? How do we want such a question to be handled? Should both (or more) questions stay open indefinitely until either is answered and somebody gets the good idea to do the duplicate linking?   As the new question is essentially a bump to the front page (perhaps with re-tagging), especially in the case where the OP knows that a previous question exist, perhaps something should be done to enable bumping re-emphasizing without writing the new question.  As I wrote this,  actually got an answer. So the old one should now be closed as a duplicate of the new - but my question remains for the case where all known/found duplicate questions have no answer?  Ironically, just before asking this, the "Questions that may already have your answer" gave me ... (Although the suggestion has no answer). So it has been asked before - the comment there even suggest the ability to re-emphasize. Why can't a single photon produce an electron-positron pair? In reading through old course material, I found the assignment (my translation):     Show that a single photon cannot produce an electron-positron pair, but needs additional matter or light quanta.   My idea was to calculate the wavelength required to contain the required energy ($1.02$ MeV), which turned out to be $1.2\times 10^{-3}$ nm, but I don't know about any minimum wavelength of electromagnetic waves. I can't motivate it with the conservation laws for momentum or energy either.  How to solve this task? Prime ideal in a polynomial ring over an integrally closed domain It seems that given a statement $a = b$, that $a + c = b + c$ is assumed also to be true.  Why isn't this an axiom of arithmetic, like the commutative law or associative law?  Or is it a consequence of some other axiom of arithmetic?  Thanks!  Edit: I understand the intuitive meaning of equality. Answers that stated that $a = b$ means they are the same number or object make sense but what I'm asking is if there is an explicit law of replacement that allows us to make this intuitive truth a valid mathematical deduction. For example is there an axiom of Peano's Axioms or some other axiomatic system that allows for adding or multiplying both sides of an equation by the same number?   In all the texts I've come across I've never seen an axiom that states if $a = b$ then $a + c = b + c$. I have however seen if $a &lt; b$ then $a + c &lt; b + c$. In my view $&lt;$ and $=$ are similar so the absence of a definition for equality is strange. Bash: What does ">|" do? I have just seen this written down;  $ some-command &gt;| /tmp/output.txt   Vertical pipes are used in standard redirects "piping" the output of one command to another, is &gt;| in fact completely useless as it would be the same as just &gt; in this scenario? Not packages and not all applications. Just the applications user installed by himself from whatever source (Software Center, manually added PPA, etc.). If the above is not possible - a list of all installed applications or at least a GUI which lists the applications so I can take screenshots of it.  I've read a dozen of similar questions and people posting answers usually don't even get close to OP question merit. Please note that my question includes 'user installed'.   Answer: It is not currently possible in Ubuntu Linux.  (choosing tijybba's answer as the closest one though) An English book tells me that the following sentence is correct:     This publication is made from paper from sustainable forests.   Shouldn't it be of paper instead? I use LINQ to Objects instructions on an ordered array.  Which operations shouldn't I do to be sure the order of the array is not changed? Which objects can I use in a finalizer method? I try to add an item to my sharepoint list from a custom web part. Is there any mistake in my code?  [WebMethod]         public static string AjouterDemande()         {             SPList ListeDemandeConge = SPContext.Current.Site.RootWeb.Lists["DEMANDE CONGÉ"];             SPListItem ListItem = ListeDemandeConge.Items.Add();             ListItem["CODE"] = code;             ListItem["DEMANDEUR"] = Utilisateur.LoginName;             ListItem["DATE DEMANDE"] = DateTime.Today.Date;             ListItem["DATE FIN"] = EndDateD;             ListItem["DATE DEPART"] = StartDateD;             ListItem["DUREE"] = int.Parse(DayCount);             ListItem["PREMIER RESPONSABLE"] = Employe.FirstSuperior.LoginName;             ListItem["DEUXIEME RESPONSABLE"] = Employe.SecondSuperior.LoginName;             ListItem["PRESENCE PRES"] = Boolean.Parse(FirstRespPresent);             ListItem["SOLDE CONGE"] = Conge.SoldeAnneeConge;             ListItem["MOIS"] = int.Parse(StartDateTab[1]);             ListItem["ANNEE"] = int.Parse(StartDateTab[0]);             ListItem["JOURS APPROUVEES"] = 0;             ListItem.Update();             ListeDemandeConge.Update();             return "true";          }   When I use F10 to process debugging step by step and get to my listitem.update(), it went out without giving any error. How are percentiles calculated in Careers 2.0? I noticed that a percentile is placed at the top of my resume in Careers 2.0.    How are these percentiles calculated? Is there a certain threshold you need to be over in order for it to be displayed? We all know , but that guidance is, naturally, geared toward main sites, where we want to keep things clean and focused.  Meta, on the other hand, is a site's "second place", with some different rules and conventions.  For example, questions on main sites can be closed as primarily-opinion-based, but meta is all about opinions.  There's a "discussion" tag and such questions collect many opinions.  Meta is different.  Occasionally I see comment flags on metas and I'm never sure what to do with them.  Setting aside things that are blatantly offensive or spam (that's a no-brainer), is there such a thing as "too chatty" or a comment discussion that should be moved to chat on meta?  I am very conservative in deleting things on per-site metas (except on  posts, which like main should stay focused).  Are there any guidelines specific to per-site metas?  I'm specifying per-site metas and not MSE because MSE seems to have conventions that fall somewhere between "main site" and "per-site meta".  If the answer is the same for all metas then great, but I don't want to assume it'll be the same. I am a super newbie for Ubuntu and basically need Ubuntu for a Python package.  I would like to run a Python file in say e:/username/folder1/folder2/python.py. I tried every method online and the only reply is bash: cd./e: No such file or directory. I am not sure whether it is because of the bash windows or virtualenv.  When I use bash on Ubuntu on Windows, ls, it says VIRTUALENV_DIR. cd, it says /home/username. The cd .. etc changes the directory a little, but not another drive, nor the folder I would like it to find. Why does QgsSpatialIndex.nearestNeighbor(point, 1) sometimes return 2 lines? I'm trying to get the closest line to a point using PyQGIS in a plugin. The active code file is this:   When I request the closest line (only 1)  nearestIds = self.spIndex.nearestNeighbor(self.feat2.geometry().centroid().asPoint(),1)   I sometimes get a list with two lines and the first one is not the closest but as far as I can see the second one is. Why is this?   Does QgsSpatialIndex use only boundingboxes for lines? How do I get the real closest line always, not only most of the time? Symbol for “such that” (not in set) Testing a UPS by unplugging it from the wall At an Not For Profit/Charity I volunteer for occasionally we were very fortunate to be provided (donated) with a brand new 3Kva APC UPS. This is total overkill for our modest server rack (four mid-range servers and a switch!) but hey, I'll take what I can get!  Pressing the TEST button on the front indicates that yes, the UPS does work. Brilliant. But it only tests it for about 15 seconds.  My question is - will I degrade the UPS by unplugging it from the wall to see how long it will last? My plan is to unplug it, and wait until the battery meter reaches its last LED before plugging it back in, so that I know about how long I will have in the event of a power outage.  Do people do this on a regular basis? I'm guessing no (Lead Acid is very different to Li-Ion batteries)... but what kind of harm would it do if this were to happen (on purpose) every 6 months?