C# 学习笔记
.Net
Build
- dotnet new
- dotnet new –list 查看所有已安装模板的列表
- dotnet new console -o projectName
- dotnet new console -n projectName
- dotnet new console –language “F#” //“C#” “F#”
- https://docs.microsoft.com/zh-cn/dotnet/core/tools/dotnet-new
- dotnet run
- dotnet publish
- dotnet build
- dotnet clean
- dotnet exec
- dotnet exec myapp.dll
- dotnet myapp.dll
- dotnet pack
- https://docs.microsoft.com/zh-cn/dotnet/core/tools/dotnet
- dotnet sln
- dotnet new sln -n slnName
- dotnet sln xxx.sln add xxx\xxx.csproj //cmd
- dotnet sln xxx.sln add **/*.csproj //bash
- Intro to VSCode for C# Developers - From Installation to Debugging
C++ | DLL
- https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute?view=net-6.0
1
2
3using System.Runtime.InteropServices;
[DllImport(@"..\..\xxx.dll",EntryPoint="Add",CallingConvention=CallingConvention.Cdecl)]
public static extern int Add(int a,int b); - DLL Edit
- VS_xxx Prompt.bat
- ildasm //查看
- ILSpy //反编译
C#基础
get set
1 |
|
Nullable
- int? i = null;
- int j = i ?? 0; //i为空,则返回0
Property || Field
- 属性是方法,应当暴露
- 字段是数据,应当被封装
Reflection
- Type
- typeof(class)
- Attribute
- type.GetCustomAttributes()
- AttributeUsage 预定义特性
- AttributeTargets
- Class
- Constructor
- Field
- Method
- Property
- AllowMultiple
- AttributeTargets
- Conditional
- Obsolete
Bitwise | 位运算
- https://www.cnblogs.com/darrenji/p/3921183.html
- https://learn.microsoft.com/zh-cn/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators
- | 位或操作符
- & 位与操作符
- ~ 取反操作符
- ^ 位异或操作符
- 当两对应的二进位相异时,结果为1
- 交换性
- r = x ^ y
- x = r ^ y
- y = r ^ x
- x、y交换
- x ^= y;
- y ^= x;
- x ^= y;
- 三次操作后,x、y已交换
- 加密、解密
1
2
3
4
5
6
7string msg = "这是我要加密的string字符串";
string k = "mypassword";
for(int i = 0; i < msg.Length; i++)
{
sb.Append((char)(msg[i] ^ k[i % k.Length]));
}
Console.WriteLine(sb.ToString());
C# 学习笔记
https://automask.github.io/wild/2021/10/25/log/P_Csharp_Feature/