using System; using System.Collections.Generic;  class MainClass {   public static void Main(string[] args) {                   int[] array = { 10, 5, 10, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12, 12 };     var dict = new Dictionary&lt;int, int&gt;();      foreach(var value in array)     {         if (dict.ContainsKey(value))             dict[value]++;         else             dict[value] = 1;     }      foreach(var pair in dict)         Console.WriteLine("Value {0} occurred {1} times.", pair.Key, pair.Value);     Console.ReadKey(); }   }   Is there a way I can make this code that counts the number of duplicate values in an array work for strings, I need it to output something like:  Donald - 2 James - 1  The numbers being the amount of times it has been repeated in the string
I have a list of items   John ID Matt ID John ID Scott ID Matt ID John ID Lucas ID   I want to shove them back into a list like so which also means I want to sort by the highest number of duplicates.   John ID 3 Matt ID 2 Scott ID 1 Lucas ID 1   Let me know how I can do this with LINQ and C#.  Thanks All  EDIT 2 Showing Code:      List&lt;game&gt; inventory = new List&lt;game&gt;();     drinkingforDataContext db = new drinkingforDataContext();     foreach (string item in tbTitle.Text.Split(' '))     {          List&lt;game&gt; getItems = (from dfg in db.drinkingfor_Games                                where dfg.game_Name.Contains(tbTitle.Text)                                select new game                                {                                    gameName = dfg.game_Name,                                    gameID = Boomers.Utilities.Guids.Encoder.EncodeURLs(dfg.uid)                                }).ToList&lt;game&gt;();          for (int i = 0; i &lt; getItems.Count(); i++)         {             inventory.Add(getItems[i]);         }     }      var items = (from xx in inventory                  group xx by xx into g                  let count = g.Count()                  orderby count descending                  select new                     {                         Count = count,                         gameName = g.Key.gameName,                         gameID = g.Key.gameID                     });      lvRelatedGames.DataSource = items;     lvRelatedGames.DataBind();   This query displays these results:   1 hello world times 1 hello world times 1 Hello World. 1 hello world times 1 hello world times 1 hello world times 1 Hello World. 1 hello world times   It gives me the count and name, but it doesn't give me the ID of the game....  It should display:   6 hello world times   234234 2 Hello World.  23432432
Why is my Nikon 50mm f/1.8 giving me an fEE error? I have a AF Nikkor 50mm f/1.8. When I have the aperture setting on the lens to 22 I can take photos. But when I change the dial to anything other than 22(lowest f/stop) then I get a flashing fEE message and r09 where the number of exposure left is.  I don't have the manual for this lens but am just wondering if anyone knows what the issue is here.  My camera is a Nikon D70S. Automatically set description list `labelwidth` based on widest label? How do I create a description list where the item text is automatically indented to the width of the widest label?  This is the same question as  but I would like the width of the widest label to be automatically calculated.  For example, I'd like the following output:    to be produced by the following input:  \documentclass{article} \usepackage{calc} \usepackage{enumitem} \usepackage{lipsum} \usepackage[margin=1em,papersize={4in,2.2in}]{geometry}  \newenvironment{mydescription}{%   \begin{description}[     leftmargin=!,     labelwidth=\magicgoeshere,     ]% }{%   \end{description}% }  \newcommand{\text}{long long long long long long long long long long   long long long long long long long long long long long long long   long long long long long long long text}  \begin{document} \begin{mydescription} \item[The longest label] text \item[Short] \text \end{mydescription} \hrule \begin{mydescription} \item[Medium label] text \item[Short] \text \end{mydescription} \end{document} Difference between correlation and covariance: is covariance only useful if the relation is linear? I'm trying to understand better the difference between  covariance and correlation, besides the fact that the correlation coefficient is a dimensional and has values between $-1$ and $1$.   One unclear point is the following: the correlation coefficient can highlight only a linear relation between two variables, but does  covariance only work for linear relations too? Supposing that the relation is not linear, is the covariance not zero? Is it bigger than in the case in which the relation is linear?   Cauchy inequality says $$|\sigma_{xy}|&lt;\sigma_{x} \sigma_{y}$$  Which seems to say that the covariance is maximum when there is a perfect linear relation.    So I do not get what does happen if the relation is not linear, and, if covariance is not a suitable parameter in that cas I don't get the reason for that, since simply looking at the definition:  $$\sigma_{xy}=\frac{\sum(x-\bar{x})(y-\bar{y})}{N}$$  it looks like that this should be non zero for any kind of relation (like parabolic).  So can this be a difference between the use of covariance and correlation coefficient? (The first is useful for any kind of relation, the second one only for linear ones). Contraction of Kronecker delta = 4 This suggests, as a shortcut notation, the concept of lowering indices; from any vector we can construct a (0, 1) tensor defined by contraction with the metric: $$A_\nu ≡ g_{\mu\nu}A^\mu$$  so that the dot product becomes $$g_{\mu\nu}A^\mu B^\nu = A_\nu B^\nu$$  We also define the inverse metric $g^{\mu\nu}$ as the matrix inverse of the metric tensor: $$g^{\mu\nu}g_{\nu\rho} = δ^\mu_\rho$$  where $δ^\mu_\rho$ is the (spacetime) Kronecker delta. (Convince yourself that this expression really does correspond to matrix multiplication.) Then we have the ability to raise indices: $$A^\mu = g^{\mu\nu}A_\nu$$ Note that raising an index on the metric yields the Kronecker delta, so we have $$g^{\mu\nu}g_{\mu\nu} = δ^\mu_\mu = 4$$  I don't understand why $δ^\mu_\mu = 4$. Shouldn't it equal 1? Analysis Question Involving Real Numbers How can I get better results when doing camera motion tracking? Whenever I do camera tracking in Blender the reconstruction is always zooming out or not on the axis. I have a great quality camera, but the end results of the camera tracking always has the model sliding. If you have a solution please tell me. Bootstrapped confidence intervals: different values at every computation? I am running an ANOVA and computing bootstrapped CIs for my effect sizes. I am using for this the Measures of Effect Size Toolbox for Matlab.  To my surprise, if I re-run the same line of code, i.e. compute the same thing for the same data, the lower&amp;upper margins of the CI are slightly different each time.  I know that bootstrapped CIs are built from permutation analyses based on random generations of distributions. Still, I do not remeber reading anywhere this odd property of CIs of being never twice the same! This code won't compile:  \documentclass{article} \usepackage{listings} \lstset{     language=C,     basicstyle=\small }  \begin{document} lorem ipsum\footnote{% \begin{lstlisting} // some C code or whatever... printf("Blah blah\n"); \end{lstlisting}} \end{document}   It says Illegal parameter number in definition of \lst@insertargs. I know listings is really picky about where it goes, but there must be a way to cram a listing into a footnote, right?  (This is a MWE and my tex files are a bit more complex; my actual error is Paragraph ended before \lst@next was complete. but they are hopefully related; I couldn't get this error with the MWE.) Purpose of asterisk before a CSS property Historical flight data outside of the USA? The question  only deals with flights in the US sourced from the  . Is there some similar source for EU, Asia etc? How does an arcane focus work with an Eldritch Knight? My PC is an Eldritch Knight. I was wondering what is an Arcane Focus? Do I need to have it in my hand? If I get the War Caster Feat does my arcane focus become obsolete? Programmatically create a user and assign a role I'm programmatically creating a user with the following code.  $newUser = array(   'name' =&gt; $mail,    'pass' =&gt; 'password',  // note: do not md5 the password   'mail' =&gt; $mail,    'status' =&gt; 1,    'init' =&gt; $mail,   'roles' =&gt; array(5) ); $user = user_save(null, $newUser);   I have got a role with the role ID equal to 5; when I create the user, in the table "users_roles" there is only a row with the value 0 for the role ID, but if I print the user object with var_dump(), it looks like the roles are created.  What am I doing wrong? I dont need this vertices and/or edge. What is the best way to get rid of them? How can I stop iPhone prompting me to setup Apple Pay in Settings? Is there any way to make a hotkey turn the screen off? How can I make a script (or make some changes) to allow me to turn the screen off in Ubuntu (12.04) whenever I want, the way thevscreen can be turned off in Cellphones?  And how can I make a combination of keys (a shortcut) to execute that script?  I want to conserve power.  I've seen this question    but there is no hotkey for it.  Moreover, in the answer, it is said that there are many ways to accomplish this so I'd like to know more. Get current URL with jQuery? I am using jQuery. How do I get the path of the current URL and assign it to a variable?  Example URL:  http://localhost/menuname.de?foo=bar&amp;amp;number=0 Upload files upto 2GB from Apex How to Start Web Mapping? I accidentally removed all the packages starting with the name jpeg with:  sudo apt-get remove jpeg*   This screwed up a lot of things, removed Unity, Firefox, Flash player etc.  I somehow managed to recover the desktop and unity but then a lot of things are still buggy. For example .rpm files and .tag.gz just won't open up at all.  What I want is a way to fix everything that's amiss. Something that is the equivalent of a 'repair installation' with a windows disc.  Any tips, anyone? I know it existed as sort of a folder in Windows Explorer in at least Windows XP, but I just can't seem to find it in Windows 7...  How can I take a picture with my webcam in Windows 7 without using any 3rd party tools?