小编Joh*_*son的帖子

C#解释中的部分方法

我很难理解部分方法的用法.

你能提供一个与linq或那种数据库事物无关的例子吗?

部分方法是相同的事情,比如当我们处于winforms并在其后面编码时,如果我们使用它被编译的方法但是如果我们不这样,那么它被编译器删除是正确的吗?

c#

12
推荐指数
2
解决办法
4520
查看次数

c#混淆中的变量范围

阅读关于线程的MSDN https://msdn.microsoft.com/en-us/library/7a2f3ay4%28v=vs.90%29.aspx我在代码中有这样一个混乱:

public class Worker
{

    public void DoWork()
    {
        while (!_shouldStop) // #1 Like here.
        {
            Console.WriteLine("worker thread: working...");
        }
        Console.WriteLine("worker thread: terminating gracefully.");
    }
    public void RequestStop()
    {
        _shouldStop = true; // #2 And here.
    }

    private volatile bool _shouldStop; 
}
Run Code Online (Sandbox Code Playgroud)

如何在声明变量_shouldStop之前使用它?检查上面的#1和#2.

c#

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

我是否应该例外阻止用户在字符串中输入{0}或{2}

像今天一样,我发现这样的事情可能会发生.我把值直接放在字符串中,但让我们说用户把它.更新示例:

   int age = 21; // Users gives age 21
   string s1 = "John {0}"; // Users gives name john and inputs this too {0}

   Console.WriteLine(s1, age); // Me wanting to show his name along with the {0} and the age

Output is :John 21
Outpout wanted is John {0} 21
Run Code Online (Sandbox Code Playgroud)

c#

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

System.Console.Write()中的奇怪行为

这样做是为了测试:

string text1 = "Letter";
string text2 = "Number";

System.Console.Write("{0}" + " {0}" + " {0}", text1, " {0}", text2);
Run Code Online (Sandbox Code Playgroud)

结果输出:

Letter Letter Letter
Run Code Online (Sandbox Code Playgroud)

这不应该是输出吗?

Letter Letter Letter Number
Run Code Online (Sandbox Code Playgroud)

这样做:

System.Console.Write("{0}" + " {0}" + " {0}", text1, " {1}", text2);
Run Code Online (Sandbox Code Playgroud)

也导致此输出:

Letter Letter Letter
Run Code Online (Sandbox Code Playgroud)

c#

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

标签 统计

c# ×4