Last active
May 10, 2018 06:23
-
-
Save sin2akshay/17ea0e52fc529150fb90d478ef48b3fd to your computer and use it in GitHub Desktop.
Code to understand using System.Collections.ObjectModel.Collection<T> Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections; | |
using System.Collections.ObjectModel; | |
class MainClass { | |
public static void Main (string[] args) { | |
Console.WriteLine ("Hello World"); | |
Collection<int> intCollection = new Collection<int>(); | |
intCollection.Add(1); | |
intCollection.Add(2); | |
intCollection.Add(3); | |
intCollection.Add(4); | |
foreach(int num in intCollection) | |
{ | |
Console.WriteLine(num); | |
} | |
//Spreading the ints in a comma separated string | |
string intColl2str = string.Join(",", intCollection.ToArray()); | |
Console.WriteLine(intColl2str); | |
Console.WriteLine("END"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run full code here: https://repl.it/@sin2akshay/ObjectModelCollectioncs
For details about the class, read: http://people.cs.aau.dk/~normark/oop-csharp/html/notes/collections_themes-list-sect.html
Difference from normal Collection: https://stackoverflow.com/questions/3118242/system-collections-vs-system-collections-objectmodel