![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C#
start_continue
这个作者很懒,什么都没留下…
展开
-
C# String 字符拼接测试(“+”、string.Format、StringBuilder 比较)
博客园首页新随笔联系订阅管理C# String 字符拼接测试(“+”、string.Format、StringBuilder 比较)对于字符串的拼接自己一直有疑问,在何时该用什么方法来拼接?哪种方法更好、更适合。几种方法1、“+” 拼接字符串现在在 C# 中,字符串进行拼接,可以直接用 “+” 而且可以直接用于数字类型的而不必转换(整形、浮点等都可以)string a = “1”;a = a + “1”;string b = “2” + 1.2345;对于使用多个 “+” 的,编原创 2021-05-24 10:26:22 · 859 阅读 · 0 评论 -
C# typeof() 和 GetType()区别
总得来说二者都是为了获取某个实例具体引用的数据类型System.Type。1、GetType()方法继承自Object,所以C#中任何对象都具有GetType()方法,x.GetType(),其中x为变量名2、typeof(x)中的x,必须是具体的类名、类型名称等,不可以是变量名称3、System.Type.GetType(),有两个重载方法比如有这样一个变量i:Int32 i = new Int32();使用GetType(),i.GetType()返回值是Int32的类型,但是无法使用typ原创 2021-05-24 10:05:40 · 129 阅读 · 0 评论 -
C#中 ??、 ?、 ?: 、?.、?[ ]
可空类型修饰符(?)引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空。例如:string str=null; 是正确的,int i=null; 编译器就会报错。为了使值类型也可为空,就可以使用可空类型,即用可空类型修饰符"?“来表示,表现形式为"T?”例如:int? 表示可空的整形,DateTime? 表示可为空的时间。T? 其实是System.Nullable(泛型结构)的缩写形式,也就意味着当你用到T?时编译器编译时会把T?编译成System.Nullable的形式。..原创 2021-05-24 09:05:31 · 92 阅读 · 0 评论 -
C#winform只允许打开一个进程
```csharpstatic void Main() { bool createdNew; using(Mutex mutex=new Mutex(true,Application.ProductName,out createdNew)) { if (createdNew) { Application.EnableVisualStyles(); .原创 2021-05-22 17:53:16 · 509 阅读 · 0 评论 -
C#客户端
using System;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using System.Windows.Forms;namespace csharp_Client{ public partial class Client : Form { public Client() { Initializ原创 2021-05-22 17:09:45 · 580 阅读 · 0 评论 -
C#服务端
/* * * 该类用于管理tcp连接通讯 * */using System;using System.Collections.Generic;using System.Net.Sockets;using System.Threading;using System.Net;namespace Communication{ /// <summary> /// 服务端 /// </summary> public class MyTc原创 2021-05-22 16:57:20 · 594 阅读 · 0 评论 -
控件太多时定位控件
可在属性列表最上方的combox查看原创 2021-05-19 08:31:47 · 53 阅读 · 0 评论 -
TCP中发送接收16进制数(16进制字符串与字节数组之间的转换)
C# tcp发送十六进制数据通讯里发送的都是byte,是不存在十六进制数据的,十六进制的全称叫十六进制字符串,也就是说比如F0,转换后就是一个byte字节,值为十进制240,只有当把收到的240转成十六进制字符串时才有F0只需要用下面方法调用,将得到的byte数组发送出去就行public static byte[] HexStringToByteArray(string s){ s = s.Replace(" ", ""); byte[] buffer = new byte[s.Le原创 2021-05-09 23:59:05 · 7903 阅读 · 1 评论