日期:2014-05-17  浏览次数:21069 次

一个有关List<T>中元素替换的问题
现在我有两个类

    //trans
    public class Trans
    {
        public string name;
        public double fix_x;
        public double fix_y;
        public Trans(string a, double b, double c)
        {
            this.name = a;
            this.fix_x = b;
            this.fix_y = c;
        }
    }
    //Nails
    public class Nails
    {
        public string name;
        public string nail;
    }

这两个类分别用List<Trans>和List<Nails>装起来的,现在我要将List<Trans>中的name替换成List<Nails>中的nail,我写了一个实现方法,但是不知道为什么返回的还是原来的List<Trans>,求解!

        public static List<Trans> change(List<Trans> a,List<Nails> b)
        {
            List<Trans> Transf_new = new List<Trans>();
            Trans nail_new;
            
            foreach (Trans nail in a)
            {
                string c = nail.name;
                foreach (Nails net in b)
                {
                    if (nail.name == net.nail)
                        c = net.name;
                }