小编ssh*_*how的帖子

IEnumerable Where()和ToList() - 他们真正做了什么?

我想知道究竟是什么Where()ToList()方法在做什么.具体来说,我想知道是否Where()会在内存中创建一个新对象或返回一个新对象.

好的,看下面的代码,说我有一个骨架日志类.

public class Log()
{
    public string Log {get;set;}
    public string CreatedByUserId {get;set;}
    public string ModifiedUserId {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

在我的业务逻辑中,假设我只想要由某个用户创建或修改的日志.这将通过一种方法完成:FilterLogsAccordingToUserId().

public IEnumerable<Log> FilterLogsAccordingToUserId(IEnumerable<Log> logs, string userId)
{
    int user = int.Parse(userId);
    return logs.Where(x => x.CreatedByUserId.Equals(user) ||
                           x.ModifiedByUserId.Equals(user)).ToList();
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,是通过删除与条件不匹配的所有对象Where()来修改IEnumerable<Log>,还是抓取所有对象,将该对象强制转换为内存中的列表,然后返回该新对象?

如果这是第二种可能性,如果将足够大的日志列表传递给函数,我是否应该关注性能?

.net c# linq

11
推荐指数
3
解决办法
3万
查看次数

String.length()是否为最终的String调用?

快速安心只是为了让您高枕无忧:
考虑以下因素

final String str = "This is the end";
Run Code Online (Sandbox Code Playgroud)

str.length()在运行时评估还是在字节码中硬编码为15?

java string final

10
推荐指数
2
解决办法
744
查看次数

C#编译器在没有错误消息的情况下崩溃

var xrr = __arglist(Convert.ToUInt32(1), 
                    Convert.ToUInt32(2), 
                    Convert.ToUInt32(3));
Run Code Online (Sandbox Code Playgroud)

上面的代码会使编译器在构建时崩溃.我希望编译器停止使用有意义的错误消息,而不是尝试编译代码.它可能是编译器中的错误吗?如果没有,我该如何解决这个错误?

.net c#

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

如何确保静态内容缓存在客户端?

如何确保缓存静态内容(图像,css,javascript)?什么是最好的方法?

asp.net iis caching browser-cache

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

MySQL在Windows上命名管道 - 更快的最佳做法,还是坏主意?

最近我一直偏爱在Windows上运行的MySQL中使用命名管道(选项--enable-named-pipes),并通过.NET连接器驱动程序连接.它通常被推荐用于安全目的,但它允许我做的一件事是连接"." 作为连接字符串并在我的PC上开发并部署到服务器而不必更改连接字符串(指向服务器主机而不是我自己的数据库副本).

更重要的是,根据我的经验,有一些加速我归因于TCP的延迟优势.我在网上发现的一些参考文献回应:

我们使用命名管道成功测试MySQL 5.0,速度有多快!在这个大项目的情况下50%首先使用来自MySQL的最新JConnector驱动程序http://www.waltercedric.com/component/content/article/1217.html可能是个好主意
.

在简单的性能测试中,命名管道访问似乎比标准TCP/IP访问快30%-50%.但是,这会因系统而异,并且在许多Windows配置中命名管道比TCP/IP慢.
http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html

但在什么"配置"它更慢?无论如何,我一直在假设本地主机访问与TCP相比更快,但是,我还没有找到任何确定的东西.也许它对于使用的特定驱动程序更具体.

mysql windows performance named-pipes

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

在Apache服务器上使用.htaccess实现缓存控制

好吧,我仍然试图了解一些缓存内容,并且我已经介绍了几个我可以在Google上找到的例子.我已将以下代码添加到我的.htaccess文件中:

### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/jpg "access plus 3 months"
ExpiresByType text/javascript "access plus 3 months"
Run Code Online (Sandbox Code Playgroud)

使用Chrome审核工具和YSlow Firebug工具,看起来这是缓存我的一些图像/文件,但不是所有这些都是.我还有一个文件列表(.jpg,.js和.css - 我知道我没有设置要缓存的css文件),这些文件不是缓存的.Chrome审核中的消息只是说明了这一点The following resources are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers:

一些不缓存的图像是背景图像,其他图像是js图库的一部分,它们是通过JS调用的 - 这可能会影响它们不缓存的原因吗?

抱歉,我无法提供代码链接 - 这些网站仍然处于封装状态,仅限于客户端视图.

提前致谢!

apache .htaccess cache-control

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

无法在Visual Studio Express 2010中选择主方法作为启动对象?

我在其中一个课程中编写了一个Main方法.我的创业公司Object说Not set.点击它时,下拉菜单中没有显示任何其他信息.为什么我不能选择main方法作为我的启动对象?我想只按ctrl + F7来运行我的主方法但是这样做时没有任何反应.以下是我正在使用的非常短的主要方法.

static void Main(string[] args)
{
    Program c = new Program();
    c.consoleread();
}
Run Code Online (Sandbox Code Playgroud)

visual-studio-2010

6
推荐指数
2
解决办法
1万
查看次数

使用iBooks App Dictionary检查单词定义

我看到iBooks App和Safari都有一个内置字典.我可以通过自己的应用程序访问此词典/单词定义吗?

在此输入图像描述

safari sdk dictionary ibooks ios

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

将文本转换为图像

我得到了使用 C# 将文本转换为图像的代码。代码如下。现在我的问题是这个函数返回一个位图图像。如何在我的 asp.net 页面中显示它。我想显示这个函数返回的图像。

private Bitmap CreateBitmapImage(string sImageText)
{
    Bitmap objBmpImage = new Bitmap(1, 1);

    int intWidth = 0;
    int intHeight = 0;

    // Create the Font object for the image text drawing.
    Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);

    // Create a graphics object to measure the text's width and height.
    Graphics objGraphics = Graphics.FromImage(objBmpImage);

    // This is where the bitmap size is determined.
    intWidth = (int)objGraphics.MeasureString(sImageText, objFont).Width;
    intHeight = (int)objGraphics.MeasureString(sImageText, objFont).Height;

    // Create the bmpImage again …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

6
推荐指数
1
解决办法
2万
查看次数

坚持使用MySQL查询

我有一个表模式

create table Location(
id int primary key,
city varchar(255),
state varchar(100),
country varchar(255)
);
create table Person( 
id int primary key,
name varchar(100)
);
create table Photographer(
id int primary key references Person(id) on update cascade on delete cascade,
livesIn int not null references Location(id) on update cascade on delete no action
);
create table Specialty(
photographer int references Photographer(id) on update cascade on delete cascade,
type enum('portrait','landscape','sport'),
primary key(photographer, type)
);
create table Photo(
id int primary key, …
Run Code Online (Sandbox Code Playgroud)

mysql sql

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