tshocktC#
延时:
System.Threading.Thread.Sleep(s);
当前时间
DateTime.Now;
UTC时间
DateTime.UtcNow;
增加时间
DateTime.UtcNow.AddHours(int 小时)
带T的日期格式
DateTime.Now.ToString("s");
格式化日期显示:
string.Format("{0:yyyyMMddHHmmssffff}",dt);
//二选一,PadLeft是在左边填空格,PadRight是在右边填空格
str.PadLeft(16); str.PadRight(16);
List升序排序:list.Sort();
List反转顺序:list.Reverse();
遍历list
List<string> 列表 = new List<string>();
列表.ForEach(item => Console.Write(item + "|"));
删除集合的两种方法:
①
plrlist.RemoveAt(list.FindIndex(t => t.姓名 == TShock.Players[args.Who].Name););
②
foreach (var temp in list)
{if (temp.姓名 == TShock.Players[args.Who].Name);
plrlist.Remove(temp);
}
//检测是否数值
int 用户id;
if (!int.TryParse(参数[1], out 用户id)){输入参数不是数值}
//当前应用程序文件名及目录
string 完整目录=Process.GetCurrentProcess().MainModule.FileNam;
string 仅目录=Path.GetDirectoryName(完整目录) + "\\";
string 仅文件名=Path.GetFileName(完整目录);
Commands.ChatCommands.Add(
new Command("ghost.ghost", //权限
new CommandDelegate(this.OnGhost),//处理函数
new string[] { "ghost", "vanish" })//命令
);
GeneralHooks.ReloadEvent += this.OnReload;//重载配置
ServerApi.Hooks.ServerChat.Register(this, OnChat);//聊天时
ServerApi.Hooks.NetGreetPlayer.Register(this, OnLine);//进入时
private void OnLine(GreetPlayerEventArgs args)
ServerApi.Hooks.ServerLeave.Register(this, OffLine);//退出时
ServerApi.Hooks.ServerJoin.Register(this, new HookHandler<JoinEventArgs>(this.OnLine));//上线时间
ServerApi.Hooks.ServerLeave.Register(this, new HookHandler<LeaveEventArgs>(this.OffLine));//下线事件
PlayerHooks.PlayerPostLogin += this.用户登录;
private void 登录时(GreetPlayerEventArgs args)
{
if (TShock.Players[args.Who] != null)
{int plrlistid = plrlist.FindIndex(t => t.姓名 == TShock.Players[args.Who].Name);
if (plrlistid < 0) {plrlist.Add(new PLR(TShock.Players[args.Who].Name, false, -1, -1, -1, -1));}
}
}
private void 离线时(LeaveEventArgs args)
{
if (TShock.Players[args.Who] != null)
{
if (plrlist.Count > 0)
{int plrlistid = plrlist.FindIndex(t => t.姓名 == TShock.Players[args.Who].Name);
if (plrlistid != -1)
{plrlist.RemoveAt(plrlistid);}
}
}
}
Array.IndexOf(数组, 查找项目);//在数组中查找及返回索引,未找到返回-1
List.indexof();查找并返回列表中的值;
多线程
for (var i = 0; i < 100; i++)
{
Thread.Sleep(100);
ThreadPool.QueueUserWorkItem(o => arrWorkMen[i].doSomething());
}
字典排序
备份文件列表 = (from item in 备份文件列表 orderby item.Key descending select item).ToDictionary(item => item.Key, item => item.Value);
扫描二维码推送至手机访问