473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

newbee need help on generic list

Hi,

For the following code snippets:

public static List<TgetListFromConfig<T>(List<TobjList, int uniqueID,
string
fileDirectory, string fileName, string configName)
where T: new()
{
//some codes to add items to objList
return objList;
}

I have the following questions:
(1) "getListFromConfig<T>", what is the purpose of <T>? Does
getListFromConfig<List<T make sense at all?

(2) What does "where T: new()" do?

(3) The function take a List<Tas the first parameter: objList, then it
returns objList. Will the following codes do the same thing?

public static void getListFromConfig<T>(List<TobjList, int uniqueID,
string
fileDirectory, string fileName, string configName)
where T: new()
{
//some codes to add items to objList
//return nothing here since objList will be sent back to the caller.
}
TIA
Jun 29 '07 #1
1 1228
On Jun 29, 7:03 am, "Raymond Du" <r...@yahoo.comwrote:
For the following code snippets:

public static List<TgetListFromConfig<T>(List<TobjList, int uniqueID,
string
fileDirectory, string fileName, string configName)
where T: new()
{
//some codes to add items to objList
return objList;

}

I have the following questions:
(1) "getListFromConfig<T>", what is the purpose of <T>?
That shows it's a generic method with one type parameter (T).
Does getListFromConfig<List<T make sense at all?
No - the bit in the angle brackets is just a list of type parameters;
List<Tisn't a type parameter, it's a generic type itself.
(2) What does "where T: new()" do?
It's a constraint which means that the method will accept a type
argument for T which has a parameterless constructor - so you could
use getListFromConfig<objectbut you couldn't use
getListFromConfig<stringfor example.
(3) The function take a List<Tas the first parameter: objList, then it
returns objList. Will the following codes do the same thing?
If it doesn't actually change the value of objList (as a variable),
yes.
However, in some cases it's useful to include a return value for the
purpose of chaining method calls together. For instance,
StringBuilder's Append methods don't really need to return anything,
but because they each return "this", you can use:

sb.Append("x").Append("y").ToString();

Jon

Jun 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Newbee Adam | last post by:
some said that .NET app can run on any program where rutime exists. What is "runtime" in this sense? will I have to install runtime or .net framework or .NET support on an xp machine for a...
3
by: Abhi | last post by:
In the following hypothetical example I want to build a generic list of unique string items. How should I implement the pred function so that it returns true/false if target string exists in the...
8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
0
by: Miguel Dias Moura | last post by:
Hello, I am saving a complex type in Asp.Net 2.0 profile. I am using an SQL 2005 database as a profile provider. I have been consulting MSDN as help to create my class. (Please, see my code...
3
by: Seth Gecko | last post by:
Hi I am working with generic lists of various objects and a control dealing with these lists. For instance: A parent form holds: dim Walls as List(Of wall) dim Segments as List(Of segment) ...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
1
by: shapper | last post by:
Hello, I created a user control (.ascx) with a property as follows: Private _Messages As Generic.List(Of String) Public Property Messages() As Generic.List(Of String) Get Return _Messages...
2
by: Mel | last post by:
I have a selection box with 3 values. what i need is to pass 3 urls to a function that has a switch statement and based on the selection index goes on one of the tree urls. Question is how do i...
1
by: Suds | last post by:
Hi, I'm having an issue with invoking a Generic method that takes Generic Arguments. My method signature is public void GenericMethodWithGenericArguments<E, V>(List<EtheFirstList,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.