无法将方法组分配给匿名类型属性c# [英] cannot assign method group to anonymous type property c#

查看:602
本文介绍了无法将方法组分配给匿名类型属性c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码使用linq我正在尝试对列表进行排序,但我列表中的x.startTime是一个表示日期时间值的字符串,我只想要日期MM / dd / yyyy。但是我遇到了这个错误。


我甚至试图做一个string.format,.toString(" MM / dd / yyyy")等等。


但我没有运气,

 var newList = callLogsOutBound.records.GroupBy(x => new {x.from.name ,Convert.ToDateTime(x.startTime).ToShortDateString})
.Select(y => new OutboundCalls()
{
Name = y.Key.name,
WeekDay = Convert.ToDateTime(y.Key.startTime)。DayOfWeek,
date = Convert.ToDateTime(String.Format(" {0:MM / dd / yyyy}",y.Key.startTime)),
Count = y.Count()

// FavoriteColor = y.Key.FavoriteColor,
//朋友= y.Key.Friend,
//学校= y.Key.School,
//儿童= y.ToList()
}
);


感谢您提供任何帮助或建议,


KSS




keith

解决方案

我想通了一个我似乎不喜欢但又有效的方式。


我循环遍历callLogsOutBound 记录并使用格式化I设置重置startTime想。


I have the following code using linq I am trying to sort my list but the x.startTime in my list is a string representing a date time value, I just want the date MM/dd/yyyy. But I am running into this error.

I have even tried to do a string.format, .toString("MM/dd/yyyy") ect..

But I have not had any luck,

var newList = callLogsOutBound.records.GroupBy(x => new { x.from.name, Convert.ToDateTime(x.startTime).ToShortDateString })
                    .Select(y => new OutboundCalls()
                    {
                        Name = y.Key.name,
                        WeekDay = Convert.ToDateTime(y.Key.startTime).DayOfWeek,
                        date = Convert.ToDateTime(String.Format("{0:MM/dd/yyyy}", y.Key.startTime)),
                        Count = y.Count()

                        //FavoriteColor = y.Key.FavoriteColor,
                        //Friend = y.Key.Friend,
                        //School = y.Key.School,
                        //Children = y.ToList()
                    }
                    );

Thanks for any help or advice,

KSS


keith

解决方案

I figured out a round about way which I don't seem to like but works.

I loop through callLogsOutBound.records and set reset startTime with the formatting I want.


这篇关于无法将方法组分配给匿名类型属性c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆