Edi Wang

Microsoft MVP for Azure

C#

C#仿魔兽世界密保卡OOP重构版

昨天下午我把《C#仿魔兽世界密保卡简单实现》 中的代码用面向对象的方法重构了一遍,引入了2个类:MatrixCard和Cell。MatrixCard描述的是密保卡,构造函数中会随机生成一个二 维矩阵,所以每次new一个MatrixCard对象,就已经生成了一张密保卡。Cell是单元格的意思,将行号、列号、列名做了封装。 MatrixCard类中保留了之前的大部分静态方法,以便灵活调用。由于本人水平有限,这次的设计并不是非常完美,并且也有一些遗憾。比如现在只能通过Cell[i]的方式来访问单元格,而不可以像Cell["A0"]这样写。有空的时候哥去研究一下重载索引器,争取把它实现。下面发代码:MatrixCard类:using System; using System.Collections.Generic; namespace GeekStudio.Common {    …
C# Refactor

C#仿魔兽世界密保卡简单实现

昨天拿C#写了个简单的密保卡程序(Console的,偷懒了一下 哈哈),实现了随机生成5x5矩阵卡、转换为字符串、从字符串读取矩阵卡以及简单验证的功能。不过我写的比较草率,代码结构不是很好,也没有体现OOP的思想,这几天有空会重构一下。先把代码发出来:public class MatrixCardManager      {          public static int[,] ReadMatrixCardFromString(string matrixStr)          {              int[,] arr1 = new int[5, 5];              int[] tempArr = new int[25];              int k = 0;              string[] tempArrStr =  …
C#

Search and Destroy Process using C#

Recently, I saw an exam system that has a feature to monitor the process. As soon as prohibited software such as Communicator.exe is found, the process is immediately killed and reported to the server. I looked into it a little bit, and this feature is actually quite simple to implement. It is to use ManagementObjectSearcher to get a list of processes, then put them in a Collection, and then you can do it according to your own logic. Here's an example: get a list of processes, create a list of "banned" processes, find and kill processes. Note that you need to add a reference to System.Management in your project first.
C# Process