问题列表 - 第13099页

将linq查询转换为字符串数组 - C#

将单列linq查询转换为字符串数组的最有效方法是什么?

private string[] WordList()
    {
        DataContext db = new DataContext();

        var list = from x in db.Words
                   orderby x.Word ascending
                   select new { x.Word };

       // return string array here
    }
Run Code Online (Sandbox Code Playgroud)

注 - x.Word是一个字符串

c# linq arrays string casting

14
推荐指数
2
解决办法
5万
查看次数

使用Hashtable只存储密钥?

可能重复:
哪个集合用于存储唯一字符串?

我目前正在使用Dictionary <string,bool>来存储唯一标识符列表.这些标识符不需要有任何与之关联的数据 - 我只是使用Dictionary来快速检查重复项.

因为我只需要键,没有值,所以是一个字典是去这里的方式,还是有另一个我不知道的收藏品会更合适?

c# collections dictionary

13
推荐指数
2
解决办法
4157
查看次数

在哪里可以找到EJB3教程?

我想学习EJB3.有人可以建议一些很好的教程网站吗?

ejb

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

ASP.NET:Literal的text属性中的单引号和双引号

简单的问题,我知道,但我似乎无法找到一种方法将单引号和双引号放入asp.net中Literal的text属性的字符串中

<asp:Literal runat="server" id="Literal1" Text="This is my "text", isn't it pretty" />
Run Code Online (Sandbox Code Playgroud)

例如,在上面的代码片段中.字符串在'text'周围的第一个双引号上关闭.我知道我可以用单引号替换它们(或使用所有双引号并用单引号包装字符串),但我不确定如何使用它们.逃避报价似乎不起作用.

当然,在代码隐藏中设置字符串是一个选项,我可以在其中转义双引号,但我一直认为最好在aspx上保留静态文本,而不是混乱代码隐藏.

asp.net formatting

17
推荐指数
2
解决办法
4万
查看次数

在std :: vector <std :: string>上使用find_if和bind2nd以及string :: compare

这似乎是一个学术问题,但我仍然对答案很感兴趣:

我有一个字符串向量s,我想在其中找到给定的字符串findme.这可以使用类似的东西来完成

find(s.begin(), s.end(), findme);
Run Code Online (Sandbox Code Playgroud)

我的问题是:必须有一种方法可以使用find_ifcompareSTL字符串的方法作为谓词,但是如何?就像是

find_if(s.begin(), s.end(), bind2nd(mem_fun_ref(&string::compare), string("findme")) );
Run Code Online (Sandbox Code Playgroud)

不起作用,因为compare方法有几个重载,编译器不知道选择哪一个.

第二步:我使用find_if而不是find的动机是我有一个从具有字符串属性的类派生的对象向量,name我想找到一个具有给定名称的对象.这是可能的(没有编写额外的函数用作谓词)?


编辑:正如使用Boost提到的一些(大多数:)答案 - 我宁愿不必为此包含Boost.(据我所知,大多数Boost库都是"唯一"模板,因此应该有一种不使用Boost的方法.)

c++ stl

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

如何从Rails获取HTTP_HOST?

我需要在rails应用程序中设置一些特定于服务器的变量,这些变量将在至少两个不同的服务器上运行.获取请求的HTTP_HOST值以获知当前服务器的最佳方法是什么,并相应地设置这些变量?我正在使用Apache 2和Passenger.

apache ruby-on-rails

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

Python:如何格式化回溯对象

我有一个traceback对象,我希望以调用时得到的漂亮格式显示traceback.format_exc().

这有内置函数吗?还是几行代码?

python format object traceback

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

Eclipse的"必备"开发工具/插件

根据这篇文章,我问$ title.哪些是您最喜欢的PHP编码相关的Eclipse插件?没有你不能活下去?为什么?
我列出了我自己的选择插件:

你的是哪一个?

php eclipse plugins favorites

13
推荐指数
2
解决办法
7440
查看次数

WPF ToggleButton IsChecked绑定问题

我试图创建一种情况,ToggleButton任何时候都可以打开两个分组中的一个或两个.我遇到的问题是,如果我更改后备变量的状态,则UI状态不会更新.

我确实已经INotifyPropertyChanged实施了.

我创建了ToggleButton这样的:

        <ToggleButton IsChecked="{Binding Path=IsPermanentFailureState, Mode=TwoWay}"
                      HorizontalContentAlignment="Center"
                      VerticalContentAlignment="Center">
            <TextBlock TextWrapping="Wrap" 
                       TextAlignment="Center">Permanent Failure</TextBlock>
        </ToggleButton>
        <ToggleButton IsChecked="{Binding Path=IsTransitoryFailureState, Mode=TwoWay}"
                      HorizontalContentAlignment="Center"
                      VerticalContentAlignment="Center">
            <TextBlock TextWrapping="Wrap" 
                       TextAlignment="Center">Temporary Failure</TextBlock>
        </ToggleButton>
Run Code Online (Sandbox Code Playgroud)

这是我的支持属性(我使用MVVM模式,其他绑定工作,IE点击ToggleButton确实输入这些属性设置.当我通过代码更改状态时,切换按钮不会改变视觉状态.IE I我将backing属性设置为false,但按钮保持选中状态.

    public bool? IsPermanentFailureState
    {
        get { return isPermFailure; }
        set
        {
            if (isPermFailure != value.Value)
            {
                NotifyPropertyChanged("IsPermanentFailureState");
            }
            isPermFailure = value.Value;
            if (isPermFailure) IsTransitoryFailureState = false;
        }
    }

    public bool? IsTransitoryFailureState
    {
        get { return isTransitoryFailureState; }
        set
        {
            if (isTransitoryFailureState != value.Value)
            {
                NotifyPropertyChanged("IsTransitoryFailureState"); …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf togglebutton

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

标题只能通过curl在php中检索

其实我有两个问题.

(1)如果我只检索标题而不是使用php和curl进行完整页面检索,那么远程服务器上使用的处理能力带宽是否会减少?

(2)由于我认为,我可能错了,第一个问题的答案是肯定的,我试图获取最后修改日期或If-Modified-Since标题的远程文件只是为了将它与时间日期进行比较本地存储的数据,所以我可以,如果它已被更改,将其存储在本地.但是,NULL当我运行这个时,我的脚本似乎无法获取那条信息:

class last_change {

 public last_change;

 function set_last_change() {
  $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://url/file.xml");
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_FILETIME, true);
    curl_setopt($curl, CURLOPT_NOBODY, true);
  // $header = curl_exec($curl);
  $this -> last_change = curl_getinfo($header);
  curl_close($curl);
 }

 function get_last_change() {
  return $this -> last_change['datetime']; // I have tested with Last-Modified & If-Modified-Since to no avail
 }

}
Run Code Online (Sandbox Code Playgroud)

如果$header = curl_exec($curl)未启用,即使我没有请求它,也会显示标题数据,如下所示:

HTTP/1.1 200 OK
Date: Fri, 04 Sep 2009 12:15:51 GMT …
Run Code Online (Sandbox Code Playgroud)

php curl header

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