List T in C

Updated on technology 2024-02-09
25 answers
  1. Anonymous users2024-02-05

    For example, I have two lists, one is the data of the string type, and the other is the data of the integer type, and when the data is not used, you need to force the data to be converted, in case you are careless, the list of the string type is forcibly converted to the integer type, isn't it wrong? The generics will let the compiler check for you, and if you want to put string data into a generic collection of the village integer type, the compiler will report an error. This way, there will be no problem of forced conversions causing errors.

    What return value a method needs to have is specified according to the need, and your method is to find out a job object that matches the requirements according to id and msg, and then return it. For example, I have a student class, and I need to look up students based on their student numbers. Static methods are created when the class is loaded, and objects of that class are created later share a method.

  2. Anonymous users2024-02-04

    First question:

    list, collection, ienumerable. Expressions of generics introduced in .NET. For example, a list defines a list, and the type of each element in the list is not limited.

    You can use it like this:

    listarray1 = new list();Define a list of integers.

    listarray2 = new list();Define a list of string types.

    Question 2:

    Public Static Job GetJob(int id, out message msg) defines a static method on the job, which can be called directly on the job without generating an object of the job class. That is, if you don't have this static keyword, you have to use job job1 = new job(), and the return value of the method can be any class.

  3. Anonymous users2024-02-03

    To give you an example, see for yourself. You get it.

    public liststrlist(string str1,string str2)

    listliststr = new list();

    str2);

    return liststr;

  4. Anonymous users2024-02-02

    The first question you should look at in C is the concept of generics and you will understand it very easily.

    The second problem is that the returned type is a class, as if it were a simple type like int char and defined as a static function to prevent other class members from calling it.

  5. Anonymous users2024-02-01

    listlist = new list();

    The same goes for other types of foreach (object obj in list).

    Since generics are also datatype. So it's actually possible to get it through gettype.

  6. Anonymous users2024-01-31

    You need to reference a namespace.

  7. Anonymous users2024-01-30

    You can use it directly.

    It should be: t is a type you define yourself, and it is not in this file, it needs to be imported before the system can recognize it.

  8. Anonymous users2024-01-29

    t is a generic parameter type placeholder, not an actual type.

    In use, you need to replace t with the type you want to use, such as list, list

  9. Anonymous users2024-01-28

    Does the incoming t exist?

  10. Anonymous users2024-01-27

    List is just a specification example of use, t represents type, and when using it, t must be replaced by your actual type. t itself does not exist.

    Like, the password input box, the content you enter, is represented by an * sign, but your actual password, must not necessarily be an * sign, in this way, it should be easy to understand.

  11. Anonymous users2024-01-26

    The list <> is a paradigm, any class can be placed in angle brackets, and an initialized instance can be added to the class instance in angle brackets. The usage is similar to arrays.

  12. Anonymous users2024-01-25

    Write in a method or function, such as a constructor.

  13. Anonymous users2024-01-24

    Yes, a set can be thought of as an array whose length can change at any time.

    The list specifies that the element type can only be a string type, and various types of elements can be added to the arraylist.

    In the case of arrays, the length of the array is already limited when it is defined at the beginning. Sometimes it's not very convenient.

  14. Anonymous users2024-01-23

    List and list are used in exactly the same way, except that list supports any type while list only supports type t, which is the type specified at definition.

    For example: listlist = new list();

    In this case, the elements in each list are strings.

    Similarly, listlist = new list();

    In this case, the elements in each list are shaped.

  15. Anonymous users2024-01-22

    The generic t is the type.

    Most of the time List performs better and is type-safe, replacing ArrayList, but if you use a value type for type t, the compiler will generate an implementation of the List class specifically for that value type. This means that you don't have to box the list element of the list object to use it, and after creating about 500 list elements, the memory saved by not boxing the list element will be greater than the memory used to generate the implementation of the class. If you want to create less than 500 elements, we recommend that you use ArrayList

  16. Anonymous users2024-01-21

    The concept of generics, just look at the relevant knowledge, I used to use datatable to be very happy, but it is still recommended to use list to get, with linq can be very convenient to implement datatable implementation is very troublesome operation, t can be any type, according to your functional needs to do it, for example:

    listlistusers = new list();

    This declares a list of myuser (a custom class), which can be directly bound to the data container control, and the specific usage is checked in msdn, which is quite detailed.

  17. Anonymous users2024-01-20

    Namespace:

    using ;

    class program

    class cls

    In simple terms, generics limit the types of operations.

    In Microsoft's words:

    Any reference or value type added to the ArrayList will be implicitly cast upwards to Object. If the item is a value type, you must bind it when you add it to the list and unbox it when you retrieve it. Forced conversions, as well as binning and unboxing operations, can degrade performance; In cases where large collections must be iterated through, the impact of binning and unboxing is very significant. ”

  18. Anonymous users2024-01-19

    list is a generic collection.

    This kind of collection specifies the data type in the collection, and can only store type t data;

    ArrayList is not generic, and any type of data can be stored in this kind of collection;

    A simple example: liststudents=new list(); Then there is no need for type conversion when reading data, i.e.: student stu=students[0]; Methods of addition, deletion, modification and search:

    t);index); delete t); Delete students= modified data check or change traversal set is similar to traversal array arraylist students=new arraylist(); student stu=students[0] as student;

  19. Anonymous users2024-01-18

    This is a new feature generic, with generics can solve the problem of boxing and unboxing, listtest = new list() is defined like this, the set of test can only be put into int data, so there is no need to (int)test[i] explicit conversion when taking out.

  20. Anonymous users2024-01-17

    You can think of it as an array of objects.

    It can also be used as another hash table.

    Actually, it's not very useful.

    Just do for(;; and foreach

    It's just a different way of writing.

  21. Anonymous users2024-01-16

    Normally, if you want to return an array of collections, you'll use it. He increases the readability of **, and through him, the person coding in the foreground can understand what this field means without much effort. For example, a users entity class is declared.

    public calss users

    This is just an object information that represents a user, if you get a list of users, you can use listuserslist = new list; Then add each user information to the list.

    users users = new users();

    ssss"; = "12";

    In this way, you can add information to the list in a loop, and then return to the list, and you can read the information in a loop on the foreground page.

  22. Anonymous users2024-01-15

    This is generic, and using generic types maximizes reuse, securing types, and improving performance.

    The most common use of generics is to create collection classes.

    You can create your own generic interfaces, generic classes, generic methods, generic events, and generic delegates.

    You can constrain a generic class to access methods of a specific data type.

    All the elements in your instance's test can only be int, and when to use them should be well understood in your actual development.

    Just do personal understanding. Hope it helps.

  23. Anonymous users2024-01-14

    Used when you need to deposit a key and a value.

  24. Anonymous users2024-01-13

    List is the use of generics, that is, it can be used to store various types, and when using the values in the list, there is no need to perform unbox operations (i.e., type conversions), but in contrast, arraylist can store various types, but it needs to perform unbox operations.

    Dictionary is obviously a store of key-value pairs, and dictionary is a good way to store key-value pairs so that values can be indexed according to the key name when needed.

  25. Anonymous users2024-01-12

    One without an index and one with an index.

    Just like a book, if there is no table of contents, then it is equivalent to a list; If the book has so, it's equivalent to a dictionary.

    You can use a dictionary when you want to create a collection with an index, and if it's purely for the purpose of documenting a dataset - not grouping, you can use a list.

    I'll give you an example:

    Zhang San: male; Li Si: female; Wang Wu: Male. If these three people are stored in the list (if only the name is saved), it is impossible to know the male and female, but if you use the dictionary, you can use "male and female" as the key, and put the name (Zhang.

    Three, Lee. 4. King 5) as a value.

Related questions
6 answers2024-02-09

Understand the following rules: 1) Overloading an operator does not change the priority of the operator. >>>More

7 answers2024-02-09

Do it by your train of thought.

Method 1. string strnumber="200m"; >>>More

9 answers2024-02-09

If you don't bring anything utilitarian to learn painting, it is purely your interest or hobby, you don't need to learn any skills at all, the skills of painting are just means, what you want to express is your thoughts, don't care about other people's evaluations, what's yours is yours, unique, and what you show may be far stronger than others, including many so-called painters. P.S. There is no shortage of painters in China, what is lacking is masters. >>>More

11 answers2024-02-09

It's textbox, right? textbook?

double somedouble; >>>More

14 answers2024-02-09

4600 super Even if the board is garbage, it will go up Although this is 690g, it should be on This board will be much worse if you add a graphics card Inherit the graphics card and then put on the independent card It will only limit the independent card So your problem now is not u but the board!