假设您要输出或连接字符串.您更喜欢以下哪种款式?
var p = new { FirstName = "Bill", LastName = "Gates" };
Console.WriteLine("{0} {1}", p.FirstName, p.LastName);
Console.WriteLine(p.FirstName + " " + p.LastName);
你更喜欢使用格式还是简单地连接字符串?什么是你最喜欢的?其中一个伤害了你的眼睛吗?
你有任何理性的论据来使用一个而不是另一个吗?
我会去第二个.
在连接字符串时,&和+运算符之间是否有任何区别?如果有,那么有什么区别?如果否,那么为什么下面的代码生成异常?
例:
    Dim s, s1, t As String
    Dim i As Integer
    s1 = "Hello"
    i = 1
    s = s1 & i
    t = s1 + i  //Exception here
    If s = t Then
        MessageBox.Show("Equal...")
    End If
哪种创建字符串的方式在运行时效率更高 C#
1号:
bool value = true;
int channel = 1;
String s = String.Format(":Channel{0}:Display {1}", channel, value ? "ON" : "OFF");
2号:
bool value = true;
String channel = "1";
string  s = ":Channel" + channel + ":Display " + value ? "ON" : "OFF";
可能重复:
C#字符串输出:格式还是concat?
使用它有什么好处:
Console.WriteLine("{0}: {1}", e.Code, e.Reason);
VS. 这个:
Console.WriteLine(e.Code + ": " + e.Reason);
????
假设我有以下字符串常量:
const string constString1 = "Const String 1";
const string constString2 = "Const String 2";
const string constString3 = "Const String 3";
const string constString4 = "Const String 4";
现在我可以用两种方式追加字符串:Option1:
string resultString = constString1 + constString2 + constString3 + constString4;
选项2:
string resultString = string.Format("{0}{1}{2}{3}",constString1,constString2,constString3,constString4);
内部string.Format使用StringBuilder.AppendFormat.现在假设我附加了常量字符串,哪个选项(option1或选项2)在性能和/或内存方面更好?
如果我有一个Effect集合,我该IEnumerable<Effect>,如何根据它们在集合中的位置设置它们的.Name属性?
所以最后,我只想让它们从1到n重命名.
<inside the collection>
effectInstance1.Name = Effect 1;
effectInstance2.Name = Effect 2;
effectInstance3.Name = Effect 3;
...
这对Linq有可能吗?
在我还在学习的时候,请对我很轻松.
以下代码:
Imports System.Console
Module Module1
    Sub Main()
        Dim num As Integer
        Dim name As String
        num = 1
        name = "John"
        WriteLine("Hello, {0}", num)
        WriteLine("Hello, {0}", name)
        WriteLine("Hello, {0}", 1)
        WriteLine("Hello, {0}", "John")
        WriteLine("5 + 5 = {0}", 5 + 5)
        WriteLine()
    End Sub
End Module
与此代码具有相同的输出:
Imports System.Console
    Module Module1
        Sub Main()
            Dim num As Integer
            Dim name As String
            num = 1
            name = "John"
            WriteLine("Hello, " & num)
            WriteLine("Hello, " & name)
            WriteLine("Hello, " & 1) …这个问题真的不难理解.我一直想知道这一点,并想知道如果可能的话,怎么办呢.如果可能的话,这就是我想做的事情:
    int number = 50;
    string text = "The number is %number";
我在上面写了%编号string,我想要number插入的值string,因为我通常会做这样的事情就像:
    int number = 50;
    string text = "The number is " + number.ToString();
是的,我整合number到string上面的方式是一种好的方式,但我总是想知道,是否有可能做一些事情,比如我写的第一个例子,在哪里把一个值object放入一个string你想要的要做的是写一些类型character或string(用于引用object),以及object进入a 的名称string得到一个string带有值的结果object吗?或者你能做什么?
我正在处理我正在处理的控制台应用程序的输出数据中的换行符时遇到问题.下面的简化示例是将outDataString写入out.txt而不使用换行符.在这种情况下,有关如何在out.txt中实现换行的任何想法?
FileStream ostrm;
StreamWriter writer;
string outDataString = "Hi, this is the out data.\nWith a few\n line breaks.";
ostrm = new FileStream("out.txt", FileMode.OpenOrCreate, FileAccess.Write);                
writer = new StreamWriter(outDataString);
Console.SetOut(writer);
Console.write(outDataString);
谢谢.
嗨,我正在为开源Javascript库编写String Interpolation.我刚刚了解了字符串插值的概念,我有点困惑?为什么我们甚至在制作字符串插值时会遇到这么多麻烦?它的优点是什么?
还有Javascript中的字符串插值的任何资源,你可以指向我吗?跟我分享?
谢谢
尝试使用连接编程...而不是说
UpdatePLOF.FolderPath = "PLOF" + plof.Id + ".txt";
尝试类似的东西:
UpdatePLOF.FolderPath = "PLOF {0} .txt", plof.Id;
对于PLOF {0} .txt告诉我只有赋值,调用,增量等...对于plof.id它告诉我; 需要
c# ×8
string ×6
.net ×2
performance ×2
vb.net ×2
asp.net ×1
coding-style ×1
ienumerable ×1
javascript ×1
linq ×1
memory ×1