Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as C# by Nux ( 13 years ago )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestConsoleApplication1
{
class Program
{
public struct User
{
public int Id;
public string Email;
}
public struct Computer
{
public int Id;
public string Name;
}
public delegate int IdGetter<in T>(T holder);
public delegate U IdSetter<in T, out U>(T holder, int newId);
private static void RewriteIListIds<T>(
IList<T> pre,
IList<T> post,
IdGetter<T> idGetter,
IdSetter<T, T> idSetter)
{
if (post != null && post.Count > 0)
{
//Assert.IsTrue(pre != null && pre.Count > 0);
for (int i = 0; i < post.Count; i++)
{
T preElement = pre[i];
T postElement = post[i];
//preElement.Id = postElement.Id;
int id = idGetter(postElement);
preElement = idSetter(preElement, id);
pre[i] = preElement;
}
}
}
static void Main(string[] args)
{
IList<User> aList = new List<User>();
IList<User> bList = new List<User>();
aList.Add(new User() {Id = 0, Email = "123@com"});
bList.Add(new User() {Id = 1, Email = "123@com"});
RewriteIListIds<User>(aList, bList, T => T.Id, (T, id) => { T.Id = id; return T; });
}
}
}
Revise this Paste
Parent: 39316