常用命令

一、string.Join 合并字符串

        struct Student
        {
            public string No;
            public string Name;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //示例一:
            List<string> arg = new List<string>();
            arg.Add("a");
            arg.Add("b");
            string s1 = string.Join("/", arg);
            MessageBox.Show(s1);


            //示例二:
            List<Student> studentList = new List<Student>();
            studentList.Add(new Student() { No = "A01", Name = "李平" });
            studentList.Add(new Student() { No = "A02", Name = "陈明" });


            string s2 = string.Join("/", studentList.OrderBy(o => o.No).Select(o => o.Name));
            MessageBox.Show(s2);
        }

二、List<T>.ForEach 方法,对 List<T> 的每个元素执行指定操作。

        struct Student
        {
            public string No;
            public string Name;
            public string Sex;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            List<Student> studentList = new List<Student>();
            studentList.Add(new Student() { No = "A1", Name = "秦天明", Sex = "男" });
            studentList.Add(new Student() { No = "A2", Name = "陈一星", Sex = "男" });
            studentList.Add(new Student() { No = "B1", Name = "李明珠", Sex = "女" });
            studentList.Add(new Student() { No = "B2", Name = "叶小娴", Sex = "女" });

            //将男生放入maleList中
            List<Student> maleList = new List<Student>();
            studentList.Where(o => o.Sex == "男").ToList().ForEach(o => maleList.Add(o));
            MessageBox.Show(string.Join("/", maleList.Select(o=>o.Name)));

            //将女生放入feMaleList中
            List<Student> feMaleList = new List<Student>();
            studentList.Where(o => o.Sex == "女").ToList().ForEach(o => feMaleList.Add(o));
            MessageBox.Show(string.Join("/", feMaleList.Select(o=>o.Name)));
        }
三、合计
            var myDm = ((PubReceiveDm)dm);
            var totalPay = myDm.DetailView.Cast<DataRowView>().Sum(o=>o.Row.Field<decimal>("PayAmt"));
            dm.CurrentItem["Amount"] = totalPay;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值