New to C# Concepts -


I am doing a crash course in C # OOP and I'm curious to know that the "LIST" keyword is the code below Shows in:

var actor = new list & lt; Actor & gt; ();

thanks

list & lt; T & gt; is a class with a type parameter, it is called "generic" and allows you to manipulate objects in a class object, especially for container classes useful for a list or queue.

A container only stores things, it really does not need to know whether it is storage, we can implement it without the generic:

  Class list {public list} {} Add public null (object to add) {/ * Add to object 'Orange' to / add '*' /} Remove zero (object to revive) {/ * Remove 'toRemove' to make the public public ] [] (Int index) {/ * storage array in index Return value * /}}  

However, we do not have type security, I can misuse the hell from that collection:

  list List = new list (); List Add (1); List Add ("Uh oh"); List Add (2); Int i = (int) list [1]; // boom becomes dynamite  

Using generic in C # allows us to use these types of container sections in a safe way.

  Category list & lt; T & gt; ; {// 'T' is our type, we do not need to know what 't' is, // we should know that it is a type. Public T Operator [] as above / / * as above * as above (as above) /} *  

Now if we like Trying to add something that we do not have, we get an error of time, which is done when our program is executed.

list & lt; Int & gt; List = new list & lt; Int & gt; (); List Add (1); // OK list Add ("not at this time"); // does not compile, you know that there is a problem

Hope that's got help. Sorry if I have made any syntax errors there, then my C # is wild;)


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -