
C# AppendFormat()
StringBuildersb=newStringBuilder();VectorcurrentPoint=newVector(0.0,0.0);sb.Append("o...
StringBuilder sb=new StringBuilder();
Vector currentPoint=new Vector(0.0,0.0);
sb.Append("origin"); 是什么意思
foreach(Vector vector in this)
{
AppendFormat(" + {0}",vector); 是什么意思
currentPoint +=vector;
} 展开
Vector currentPoint=new Vector(0.0,0.0);
sb.Append("origin"); 是什么意思
foreach(Vector vector in this)
{
AppendFormat(" + {0}",vector); 是什么意思
currentPoint +=vector;
} 展开
展开全部
sb.Append("origin"); 是什么意思
在 sb的后面再加上 origin 这几个字母。(可以把sb就理解成一个字符串你就明白了)
AppendFormat(" + {0}",vector); 是什么意思
添加的字符串格式是 (" + {0}",vector 说的是: 一个 + 和一个参数 ,这个参数的值是遍历的vector的值
在 sb的后面再加上 origin 这几个字母。(可以把sb就理解成一个字符串你就明白了)
AppendFormat(" + {0}",vector); 是什么意思
添加的字符串格式是 (" + {0}",vector 说的是: 一个 + 和一个参数 ,这个参数的值是遍历的vector的值

2022-08-05 广告
苏州蓝晓生物科技有限公司。标准化核心产品:公司拥有完整的琼脂糖介质、葡聚糖介质、聚甲基丙烯酸酯介质生产线,年产分离介质50000L,产品质量稳定并达到国际领先水平。核心优势:公司核心技术人员拥有近二十年不同基质的基球开发和官能化的丰富技术经...
点击进入详情页
本回答由苏州蓝晓生物科技有限公司_提供
2015-12-24 · 知道合伙人软件行家
关注

展开全部
AppendFormat is available on StringBuilder. With it we append different kinds of data—including string literals—to an underlying string buffer. With it we create code that is clearer to read and modify. It handles formatting strings.StringBuilder Append
Example. This first example shows how to use a string literal to generate sentences in your StringBuilder. You can put parenthesis around values, which would be more confusing syntactically if you were to use string concatenation.
Tip:The core reason to use AppendFormat here is for clarity of the resulting code. It is clear to see what string data will be generated.
string.ConcatC# program that uses AppendFormat
using System;
using System.Text;
class Program
{
static void Main()
{
StringBuilder builder = new StringBuilder();
string[] data = { "Dot", "Net", "Perls" };
int counter = 0;
foreach (string value in data)
{
builder.AppendFormat("You have visited {0} ({1}).\n",
value,
++counter);
}
Console.WriteLine(builder);
}
}
Output
You have visited Dot (1).
You have visited Net (2).
You have visited Perls (3).
Example 2. Here we use the AppendFormat method on the StringBuilder type. Format strings in the C# language are a powerful of simplifying string changes for display. The AppendFormat method uses the same syntax.
Also:There are many advanced rules for string formatting, which are not covered in this document.
string.FormatProgram 2: C#
using System;
using System.Text;
class Program
{
static int[] _v = new int[]
{
1,
4,
6
};
static void Main()
{
StringBuilder b = new StringBuilder();
foreach (int v in _v)
{
b.AppendFormat("int: {0:0.0}{1}", v,
Environment.NewLine);
}
Console.WriteLine(b.ToString());
}
}
Output
int: 1.0
int: 4.0
int: 6.0
Summary. The StringBuilder AppendFormat method is useful for generating text based on a pattern. The method receives a variable number of arguments. We specified new lines in the AppendFormat method in both examples.
Note:For optimal code clarity, the AppendFormat method is ideal. It is not ideal for performance.
Example. This first example shows how to use a string literal to generate sentences in your StringBuilder. You can put parenthesis around values, which would be more confusing syntactically if you were to use string concatenation.
Tip:The core reason to use AppendFormat here is for clarity of the resulting code. It is clear to see what string data will be generated.
string.ConcatC# program that uses AppendFormat
using System;
using System.Text;
class Program
{
static void Main()
{
StringBuilder builder = new StringBuilder();
string[] data = { "Dot", "Net", "Perls" };
int counter = 0;
foreach (string value in data)
{
builder.AppendFormat("You have visited {0} ({1}).\n",
value,
++counter);
}
Console.WriteLine(builder);
}
}
Output
You have visited Dot (1).
You have visited Net (2).
You have visited Perls (3).
Example 2. Here we use the AppendFormat method on the StringBuilder type. Format strings in the C# language are a powerful of simplifying string changes for display. The AppendFormat method uses the same syntax.
Also:There are many advanced rules for string formatting, which are not covered in this document.
string.FormatProgram 2: C#
using System;
using System.Text;
class Program
{
static int[] _v = new int[]
{
1,
4,
6
};
static void Main()
{
StringBuilder b = new StringBuilder();
foreach (int v in _v)
{
b.AppendFormat("int: {0:0.0}{1}", v,
Environment.NewLine);
}
Console.WriteLine(b.ToString());
}
}
Output
int: 1.0
int: 4.0
int: 6.0
Summary. The StringBuilder AppendFormat method is useful for generating text based on a pattern. The method receives a variable number of arguments. We specified new lines in the AppendFormat method in both examples.
Note:For optimal code clarity, the AppendFormat method is ideal. It is not ideal for performance.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string name="热心网友";
string sex="男";
int age=19;
StringBuilder str=new StringBuilder();
str.AppendFormat("我的名字是:{0},性别:{1},年龄:{2}",name,sex,age);
类似与上面这种形式!
string sex="男";
int age=19;
StringBuilder str=new StringBuilder();
str.AppendFormat("我的名字是:{0},性别:{1},年龄:{2}",name,sex,age);
类似与上面这种形式!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
格式化构造字符串……这里应该是用于把向量组里的坐标连续输出
详情请查询MSDN
详情请查询MSDN
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询