小编E.V*_*han的帖子

如何使用LINQ to Entities获取字节数组长度?

我有一个Document类,它将该文档的数据存储为字节数组.我需要使用LINQ to Entities来检查数组的大小.

我尝试过以下方法:

[long Linq query here...] o.Data.Length < 800000)
Run Code Online (Sandbox Code Playgroud)

问题是我得到以下异常:

LINQ to Entities中不支持LINQ表达式节点类型'ArrayLength'."

有没有其他方法来检查字节数组的大小?

c# linq arrays linq-to-entities

10
推荐指数
1
解决办法
3500
查看次数

明智地使用try/catch

我希望这个话题不会太哲学:)

一般来说,我正在开发一个与外部世界有很多联系的应用程序.您可以保存和读取文件,连接到数据库,读取通过TCP协议传输的数据包,将打印任务发送到打印机,解析用户文本输入等.理论上,这些操作中的每一个都可能以许多可能的方式出错.

我的问题是我已经厌倦了为数百条指令编写try/catch块.它使代码长两倍,读取更糟糕,而不是做一些"真正的"编码,我继续写日志,这可能永远不会发生.

但还有其他选择吗?

你的方法是什么?制作所有这些try/catch块?或者只是忽略这些可能的错误并仅在用户报告后处理ACTUAL错误?

Should we never allow application to crash, should we predict any stupid action by an user or is it user problem not to do stupid actions?

And is it better to put big blocks of code into try/catch or put single instructions into it?

I'd be grateful for any advice or just opinion.

c# error-handling try-catch

1
推荐指数
1
解决办法
112
查看次数

标签 统计

c# ×2

arrays ×1

error-handling ×1

linq ×1

linq-to-entities ×1

try-catch ×1