Note that there are some explanatory texts on larger screens.

plurals
  1. POlinq related question
    primarykey
    data
    text
    <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Comparer.csd { class Program { /* Confusion is regarding how ToList() method works. Does it do the deep copy or shallow copy?? /**********OUTPUT a a b a b c a c a ----------------- a a b a c a ----------------- 1 2 3 OUTPUT ENDS************/ static void Main(string[] args) { List&lt;test&gt; list = new List&lt;test&gt;(); list.Add(new test("a", "b", "c")); list.Add(new test("a", "c", "a")); list.Add(new test("a", "a", "b")); /// sort the list based on first name and last name IEnumerable&lt;test&gt; soretedCollection = from t in list orderby t._fname ascending, t._mname ascending select t; Print(soretedCollection); /// remove the first object from the list list.RemoveAt(0); /// print the list . /// Removal of the item from the list is reflected here so I guess sorted collection and list both /// are refering the same data structure /// what if I will do /// list = soretedCollection.ToList&lt;test&gt;(); /// is it going to change the reference of the list if some other object /// is holding the reference?? Print(soretedCollection); Dictionary&lt;int, int&gt; dic = new Dictionary&lt;int, int&gt;(); dic.Add(1, 1); dic.Add(2, 1); dic.Add(3, 1); List&lt;int&gt; keys = dic.Keys.ToList&lt;int&gt;(); /// remove the dictionary entry with key=2 dic.Remove(2); /// how come this time it did not remove the second item becuase it is removed from the dictionary. for (int i = 0; i &lt; keys.Count; ++i) { Console.WriteLine(keys[i].ToString()); } Console.Read(); } static void Print(IEnumerable&lt;test&gt; list) { foreach (test t in list) { t.Print(); } Console.WriteLine("---------------------"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload