详解C#中的字符串拼接@ $
作者:胜天半子_王二_王半仙 时间:2021-07-10 13:13:41
一:@
@的意思是以@标注的字符出,其中所有的符号均为字符串符号,没有什么特殊字符,如''什么的,均默认为字符串
static void Main(string[] args)
{
//这样就很方便写读取的文件路径,也不需要什么转义字符了
StreamReader sr = new StreamReader(@"C:\Users\WANGWI8\Desktop\testStreamRead.txt");
string line;
while( (line = sr.ReadLine()) != null )
{
Console.WriteLine(line);
}
}
二:$
$的意思是以它标注的字符串中,可用中括号取值:
static void Main(string[] args)
{
var name = Console.ReadLine();
var date = DateTime.Now;
var result = $"hello {name} , you are my father , i am your son , writed at {date}";
Console.WriteLine(result);
var item2 =
(
name: "william",
sex: 'f'
);
Console.WriteLine($"this is item : item.name : {item2.name} , this is sex : {item2.sex}");
var inventory = new Dictionary<string, int>()
{
["hammer, ball pein"] = 18,
["hammer, cross pein"] = 5,
["screwdriver, Phillips #2"] = 14
};
Console.WriteLine($"inventory on {DateTime.Now:d}");
Console.WriteLine(" ");
//负号的意思是左对齐,一共占据25个字符的空间
Console.WriteLine($"|{"item",-25}|{"quantity",10}|");
foreach (var item in inventory)
Console.WriteLine($"|{item.Key,-25}|{item.Value,10}|");
}
总结
以上所述是小编给大家介绍的C#中的字符串拼接@ $,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/qq_40666620/article/details/101695138
标签:c#,字符串,拼接
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring事务管理配置文件问题排查
2022-07-04 15:55:25
![](https://img.aspxhome.com/file/2023/4/76584_0s.png)
IDEA 插件 mapper和xml互相跳转操作
2021-07-19 02:48:13
![](https://img.aspxhome.com/file/2023/4/66024_0s.jpg)
使用@pathvariable与@requestparam碰到的一些问题及解决
2023-11-27 16:30:34
![](https://img.aspxhome.com/file/2023/9/60459_0s.png)
旧项目升级新版Unity2021导致Visual Studio无法使用的问题
2023-12-28 21:51:26
![](https://img.aspxhome.com/file/2023/6/126006_0s.png)
C#+MO实现一个道路编辑软件(刚开始)
2023-03-28 08:52:05
Java源码解析LinkedList
2023-04-28 02:56:18
Springboot整合FreeMarker的实现示例
2023-04-09 00:57:57
![](https://img.aspxhome.com/file/2023/3/76593_0s.jpg)
java简单工厂模式入门
2022-12-03 04:35:24
spring中12种@Transactional的失效场景(小结)
2022-04-26 00:06:40
![](https://img.aspxhome.com/file/2023/3/103993_0s.jpg)
Spring AOP实现打印HTTP接口出入参日志
2021-10-09 13:38:37
![](https://img.aspxhome.com/file/2023/1/78371_0s.png)
c# HttpClient设置超时的步骤
2023-05-07 10:42:29
C#将布尔类型转换成字节数组的方法
2023-06-21 15:30:16
java获取和设置系统变量问题(环境变量)
2023-11-19 07:34:07
![](https://img.aspxhome.com/file/2023/3/58863_0s.png)
Android仿淘宝商品详情页
2023-09-08 18:37:26
![](https://img.aspxhome.com/file/2023/6/111726_0s.gif)
mybatis源码解读-Java中executor包的语句处理功能
2023-09-03 06:34:16
简单了解Java方法的定义和使用实现
2021-11-07 06:12:53
![](https://img.aspxhome.com/file/2023/1/126351_0s.png)
Java中死锁与活锁的具体实现
2023-10-29 01:48:02
![](https://img.aspxhome.com/file/2023/4/80844_0s.jpg)
C# Winform中如何绘制动画示例详解
2022-03-28 13:26:26
半小时实现Java手撸网络爬虫框架(附完整源码)
2022-11-23 15:59:35
Mybatis TypeHandler接口及继承关系示例解析
2021-11-19 03:33:34
![](https://img.aspxhome.com/file/2023/6/82986_0s.png)