小编Mat*_*hew的帖子

如何在正则表达式列表中找到与我的输入匹配的第一个正则表达式?

有没有其他方式写下面的内容?

string input;

var match = Regex.Match(input, @"Type1");

if (!match.Success)
{
  match = Regex.Match(input, @"Type2");
}

if (!match.Success)
{
  match = Regex.Match(input, @"Type3");
}
Run Code Online (Sandbox Code Playgroud)

基本上,我想通过一系列表达式运行我的字符串,看看哪一个坚持.

c# regex

5
推荐指数
3
解决办法
1445
查看次数

为什么String.Contains在此查询中不区分大小写?

我正在通过这个ASP MVC教程.本教程的这一页面涉及编写一个简单的"搜索"页面.控制器包含此方法:

public ActionResult SearchIndex(string searchString) 
{           
     var movies = from m in db.Movies 
                  select m; 

    if (!String.IsNullOrEmpty(searchString)) 
    { 
        movies = movies.Where(s => s.Title.Contains(searchString)); 
    } 

    return View(movies); 
}
Run Code Online (Sandbox Code Playgroud)

根据MSDN,String.Contains区分大小写.但是当我导航到时[website url]/Movies/SearchIndex?searchString=mel,它会返回一个带有标题的电影Melancholia.如果我检查控制器方法在调试器,searchStringmel(小写)如预期.

为什么String.Contains这个标题不区分大小写?

.net c# linq asp.net-mvc asp.net-mvc-4

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

有没有办法在不关闭底层流的情况下关闭Writer?

我有一个套接字,我写了一些字符数据和一些原始字节数据.对于角色数据,使用a更容易PrintWriter.对于原始字节数据,更容易直接写入OutputStream.所以在我的代码中,我有这样的段:

Writer writer = new PrintWriter(outputStream);
writer.write(someText);
...
writer.flush();
// No call to writer.close(), because that would close the underlying stream.
Run Code Online (Sandbox Code Playgroud)

只要我Writer在开始以其他方式写入流后不小心写这个,这很好.但是我宁愿安全地知道IOException如果我不小心写了一个流,我会得到一个(就像我关闭它一样).

有没有办法明确地防止将来写入a Writer而不关闭其底层流?

java sockets io outputstream

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

了解没有线程的异步/等待

根据MSDN,asyncawait没有创建新线程:

asyncawait关键字不会导致创建额外的线程.

考虑到这一点,我很难理解一些简单程序的控制流程.我的完整示例如下.请注意,它需要Dataflow库,您可以从NuGet安装它.

using System;
using System.Threading.Tasks.Dataflow;

namespace TaskSandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            BufferBlock<int> bufferBlock = new BufferBlock<int>();

            Consume(bufferBlock);
            Produce(bufferBlock);

            Console.ReadLine();
        }

        static bool touched;
        static void Produce(ITargetBlock<int> target)
        {
            for (int i = 0; i < 5; i++)
            {
                Console.Error.WriteLine("Producing " + i);
                target.Post(i);
                Console.Error.WriteLine("Performing intensive computation");
                touched = false;
                for (int j = 0; j < 100000000; j++)
                    ;
                Console.Error.WriteLine("Finished intensive computation. …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading task-parallel-library async-await

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

这个包含尖括号的符号是什么意思?

在C#5.0中阅读Async,编译器转换部分包含以下代码段:

public Task<int> AlexsMethod()
{
    <AlexsMethod>d__0 stateMachine = new <AlexsMethod>d__0();
    stateMachine.<>4__this = this;
    stateMachine.<>t__builder = AsyncTaskMethodBuilder<int>.Create();
    stateMachine.<>1__state = -1;
    stateMachine.<>t__builder.Start<<AlexsMethod>d__0>(ref stateMachine);
    return stateMachine.<>t__builder.Task;
}
Run Code Online (Sandbox Code Playgroud)

有两段符号对我来说是新的.首先是<AlexsMethod>d__0.第二是stateMachine.<>4__this.当我自己尝试时它们都不起作用,所以我怀疑它只供编译器使用.但是我在搜索有关这种符号的意图的更多信息时遇到了麻烦.

.net c# syntax notation async-await

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

我想隐藏图像并在悬停在其上时显示文本

我想将鼠标悬停在我的图像上,并将文本显示在图像的位置,但我不想使用jQuery或JavaScript.

#wrapper .text {
  position: relative;
  bottom: 30px;
  left: 0px;
  visibility: hidden;
}
#wrapper:hover .text {
  visibility: visible;
}
Run Code Online (Sandbox Code Playgroud)
<div id="wrapper">
  <img src="kero.png" class="hover" height="200px" width="200px/>
  <p class="text">text</p>
</div>?
Run Code Online (Sandbox Code Playgroud)

html css

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

python如何确定参数是引用还是值?

在C++中,void somefunction(int)传递一个值,同时void somefunction(int&)传递一个引用.在Java中,基元通过值传递,而对象通过引用传递.python是如何做出这个决定的?

编辑:因为所有内容都是通过引用传递的,为什么会这样:

def foo(num):
    num *= 2

a = 4
foo(a)

print(a)
Run Code Online (Sandbox Code Playgroud)

打印'4'而不是'8'?

python pointers reference

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

这个C#语法的名称是什么?

在C#中,你可以这样做:

SomeClass someClass = new SomeClass () {
    SomeProperty = someValue
};
Run Code Online (Sandbox Code Playgroud)

这个语法叫什么?

c# syntax object-initializers

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

在Ant中,目标内的任务顺序是否重要?

我想制作一个重启tomcat6的目标.现在,我有这样的事情:

<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
<taskdef name="start" classname="org.apache.catalina.ant.StartTask" />

...

<target name="restart" depends="deploy" description="Restart Tomcat" >
    <stop url="${manager}" username="${username}" password="${password}" path="${path}" />
    <start url="${manager}" username="${username}" password="${password}" path="${path}" />
</target>
Run Code Online (Sandbox Code Playgroud)

我可以在开始前依赖停止运行吗?或者我应该制作两个单独的目标,并且"开始"依赖于"停止"?

java ant tomcat

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

这两种算法之间是否存在改变IEnumerable的性能差异?

这两个问题为洗刷IEnumerable提供了类似的算法:

以下是两种方法并排:

public static IEnumerable<T> Shuffle1<T> (this IEnumerable<T> source)
{
    Random random = new Random ();
    T [] copy = source.ToArray ();

    for (int i = copy.Length - 1; i >= 0; i--) {
        int index = random.Next (i + 1);
        yield return copy [index];
        copy [index] = copy [i];
    }
}


public static IEnumerable<T> Shuffle2<T> (this IEnumerable<T> source)
{
    Random random = new Random ();
    List<T> copy = source.ToList ();

    while (copy.Count > 0) {
        int index …
Run Code Online (Sandbox Code Playgroud)

c# linq performance ienumerable

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