As I understand Linked Lists are useful if I need a list where I need to remove, or add items multiple times after the declaration - things that are not possible/harder to do with an array. But basically I can do the same thing with List Class in C#. So my question is, what is the difference between the two?
87500
When is it better to use a  vs a ?
31631
I think we all understand the necessity of delete when reassigning a dynamically-allocated pointer in order to prevent memory leaks. However, I'm curious, to what extent does the C++ mandate the usage of delete? For example, take the following program  int main() {      int* arr = new int[5];      return 0; }   While for all intents and purposes no leak occurs here (since your program is ending and the OS will clean up all memory once it returns), but does the standard still require -- or recommend -- the usage of delete[] in this case? If not, would there be any other reason why you would delete[] here?
80312
In C# 3.0 you can create anonymous class with the following syntax  var o = new { Id = 1, Name = "Foo" };   Is there a way to add these anonymous class to a generic list?  Example:  var o = new { Id = 1, Name = "Foo" }; var o1 = new { Id = 2, Name = "Bar" };  List&lt;var&gt; list = new List&lt;var&gt;(); list.Add(o); list.Add(o1);   Another Example:  List&lt;var&gt; list = new List&lt;var&gt;();  while (....) {     ....     list.Add(new {Id = x, Name = y});     .... }
22662
In what scenarios is it better to use a struct vs a class in C++?
21215
I have just noticed that a multidimensional array in C# does not implement IEnumerable&lt;T&gt;, while it does implement IEnumerable. For single-dimensional arrays, both IEnumerable&lt;T&gt; and IEnumerable are implemented.  Why this difference? If a multi-dimensional array is IEnumerable, surely it should also implement the generic version? I noticed this because I tried to use an extension method on a multidimensional array, which fails unless you use Cast&lt;T&gt; or similar; so I can definitely see the an argument for making multidimensional arrays implement IEnumerable&lt;T&gt;.  To clarify my question in code, I would expect the following code to print true four times, while it actually prints true, false, true, true:  int[] singleDimensionArray = new int[10]; int[,] multiDimensional = new int[10, 10];  Debug.WriteLine(singleDimensionArray is IEnumerable&lt;int&gt;); Debug.WriteLine(multiDimensional is IEnumerable&lt;int&gt;); Debug.WriteLine(singleDimensionArray is IEnumerable); Debug.WriteLine(multiDimensional is IEnumerable);
72626
What's the difference between struct and class in .NET?
117196
I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.  Say we have a linked list record defined so:  typedef struct _record {     char* value;     struct _record* next; } record;   We need a function that inserts a new record so that the entire list remains sorted with respect to the value's in the records. The following implementation is simpler than anything I would have used, albeit less readable.  void insert_sorted(record** r, const char* value) {     record* newrec = NULL;     while(*r &amp;&amp; strcmp(value, (*r)-&gt;value) &gt; 0)         r = &amp;((*r)-&gt;next); /* move r to point to the next field of the record */     newrec = malloc(sizeof(record));     newrec-&gt;value = strdup(value);     newrec-&gt;next = *r;     *r = newrec; }   When the function is called, r points to the head pointer of the list. During the while loop, r is updated to point to the next field of the record that comes just before the point where we want to put the new record in. The last line of the function either updates the head pointer of the list (if the insertion happens at the beginning) or the next field of the previous record, which is quite cool.  A couple of questions:   Does this idiom have a name or is it mentioned in any literature? Are there others like it in the C language?   I thought I knew C pretty well and had pointers and indirection pretty well figured out, but this one took me a while to fully understand.
37849
I'm working on a project in C#. The previous programmer didn't know object oriented programming, so most of the code is in huge files (we're talking around 4-5000 lines) spread over tens and sometimes hundreds of methods, but only one class. Refactoring such a project is a huge undertaking, and so I've semi-learned to live with it for now.  Whenever a method is used in one of the code files, the class is instantiated and then the method is called on the object instance.  I'm wondering whether there are any noticeable performance penalties in doing it this way? Should I make all the methods static "for now" and, most importantly, will the application benefit from it in any way?
108808
Does a List&lt;T&gt; always guarantee that items will be returned in the order they were added when enumerated?  Updated: Thanks for all the answers folks, puts my mind at ease. I had a quick poke around the List&lt;T&gt; class with .NET Reflector (should've probably done that in the first place) and indeed the underlying store is an array of T (T[]).
72761
I know that IList is the interface and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to decide when to use the interface or the concrete type?
107554
Is it possible in C# to have a Struct with a member variable which is a Class type?  If so, where does the information get stored, on the Stack, the Heap, or both?
92781
For a simple linked list in which random access to list elements is not a requirement, are there any significant advantages (performance or otherwise) to using std::list instead of std::vector?  If backwards traversal is required, would it be more efficient to use std::slist and reverse() the list prior to iterating over its elements?
46642
Let's say I have a class that has a member called data which is a list.    I want to be able to initialize the class with, for example, a filename (which contains data to initialize the list) or with an actual list.  What's your technique for doing this?  Do you just check the type by looking at __class__?  Is there some trick I might be missing?  I'm used to C++ where overloading by argument type is easy.
23150
Can someone give an example of a good time to actually use "unsafe" and "fixed" in C# code? I've played with it before, but never actually found a good use for it.   Consider this code...  fixed (byte* pSrc = src, pDst = dst) {     //Code that copies the bytes in a loop }   compared to simply using...  Array.Copy(source, target, source.Length);   The second is the code found in the .NET Framework, the first a part of the code copied from the Microsoft website, .  The built in Array.Copy() is dramatically faster than using Unsafe code. This might just because the second is just better written and the first is just an example, but what kinds of situations would you really even need to use Unsafe/Fixed code for anything? Or is this poor web developer messing with something above his head?
69502
Possible Duplicate:          Would someone explain the differences between these two beasts and how to use them. AFAIK, many  pre.2.0 classes were implemented without generic types, thus causing latter version to implement both flavors of interfaces. Is the the only case why one would need to use them?  Can you also explain in depth how to use them.?  Thanks
73638
Is there any advantage over using a class over a struct in cases such as these?  (note: it will only hold variables, there will never be functions)  class Foo {  private:       struct Pos { int x, y, z }; public:        Pos Position;  };   Versus:  struct Foo {    struct Pos { int x, y, z } Pos; };     Similar questions:
43660
I have a list of structs and I want to change one element. For example :  MyList.Add(new MyStruct("john"); MyList.Add(new MyStruct("peter");   Now I want to change one element:  MyList[1].Name = "bob"   However, whenever I try and do this I get the following error:     Cannot modify the return value of   System.Collections.Generic.List.this[int]‘ because it is not   a variable   If I use a list of classes, the problem doesn't occur.  I guess the answer has to do with structs being a value type.  So, if I have a list of structs should I treat them as read-only? If I need to change elements in a list then I should use classes and not structs?