Using Statement with Generics: Using Iset<> = System.Collections.Generic.Iset<>

Using Statement with Generics: using ISet = System.Collections.Generic.ISet

I think you're better off aliasing the namespaces themselves as opposed to the generic types (which I don't think is possible).

So for instance:

using S = System.Collections.Generic;
using I = Iesi.Collections.Generic;

Then for a BCL ISet<int>, for example:

S.ISet<int> integers = new S.HashSet<int>();

Using Statement with Generics: using ISet = System.Collections.Generic.ISet

I think you're better off aliasing the namespaces themselves as opposed to the generic types (which I don't think is possible).

So for instance:

using S = System.Collections.Generic;
using I = Iesi.Collections.Generic;

Then for a BCL ISet<int>, for example:

S.ISet<int> integers = new S.HashSet<int>();

What's the implementation of List?

The implementation of List<T> can't be shown from Visual Studio because it doesn't have the source code present. It just shows the outline of the class (that is why Visual Studio puts [metadata] on top of the 'code file' when hitting F12).

The actual source can be found on referencesource.microsoft.com.

If List equals ArrayList or something, why .net will allow two class which equals function but different name? If List doesn't equal any other class in .NET, so why give it such an ambiguous name?

No, they are not the same. ArrayList is a non-generic list implementation, while List<T> is generic, and thus strongly typed.

Regarding the ambiguous name: I think Microsoft is right in their naming of List. ArrayList was a terrible name anyway. It emphasizes the implementation too much. You don't care there is an array behind it: to you it is just a List. Given that the name was available, this was a good option for a name.

cannot implicitly convert type int to system collections generic listint

I believe you need to rework your model. Your current model would have a list of one product id and one order id. Why have a list containing one thing? Won't you want to know which products are associated with which orders?

internal class ProductOrderDetail
{
public int ProductId { get; set; }
public int OrderId { get; set; }
}

public IEnumerable<ProductOrderDetail> GetProductOrderDetail(IEnumerable<int> productIds, IEnumerable<int> OrderIds)
{
var query = (from p in products
join o in orders on p.productId equals o.product_id_fk
where o.customerId_fk == this.CustomerId
where productIds.Contains(p.productId)
where orderIds.Contains(o.orderId)
select new ProductOrderDetail()
{
ProductId = p.productId,
OrderId = o.orderId
});

return query;
}

Usage:

var productIds = { 1, 2, 3 };
var orderIds = { 11154, 13157 };

List<ProductOrderDetail> results = GetProductOrderDetail(productIds, OrderIds).ToList();

This gets you a list of product/order id pairs.

.NET Generic Set?

HashSet<T> in .NET 3.5

cannot implicitly convert from type void to Systems.Collections.Generics.List

Your use of the ternary operator...

job.TestNodes = string.IsNullOrEmpty(columns[2]) ? job.TestNodes : testNodes.Add(new TestNode(nodeCounter += 1, "JobExecutor", columns[2], 0));

...effectively works like this...

if (string.IsNullOrEmpty(columns[2]))
{
job.TestNodes = job.TestNodes;
}
else
{
job.TestNodes = testNodes.Add(new TestNode(nodeCounter += 1, "JobExecutor", columns[2], 0));
}

The List<>.Add() method has this signature...

public void Add (T item);

void means it doesn't return anything. You can't assign the result of a void method to some other storage because there is no result to assign. (Note that this is different than a method that happens to return null.)

To fix this, perform your call to Add() and subsequent List<> assignment separately...

if (string.IsNullOrEmpty(columns[2]))
{
job.TestNodes = job.TestNodes;
}
else
{
testNodes.Add(new TestNode(nodeCounter += 1, "JobExecutor", columns[2], 0));
job.TestNodes = testNodes;
}

Since the true branch of the if block is effectively a no-op, we can rewrite that as simply...

if (!string.IsNullOrEmpty(columns[2]))
{
testNodes.Add(new TestNode(nodeCounter += 1, "JobExecutor", columns[2], 0));
job.TestNodes = testNodes;
}

Depending on how job.TestNodes gets assigned it might be necessary to instead do...

job.TestNodes = testNodes;
if (!string.IsNullOrEmpty(columns[2]))
{
testNodes.Add(new TestNode(nodeCounter += 1, "JobExecutor", columns[2], 0));
}

Cannot Convert Type System.Collection.Generic.ListT

If ProcessUser et al does not require a list and can work with just an IEnumerable<T> then you can simplify it a bit:

public boolean ProcessUser(IEnumerable<JSONUser> JSONList)
{
...
}

public boolean ProcessCompany(IEnumerable<JSONCompany> JSONList)
{
...
}

Then just call it with:

boolean result = ProcessUser(oJSON.Cast<JSONUser>());

otherwise you could create a new list:

boolean result = ProcessUser(oJSON.Cast<JSONUser>().ToList());

which may be fine if you're just iteerating/modifying the objects in the list and not the list itself. (adding/removing/sorting/etc.)



Related Topics



Leave a reply



Submit