Skip to content

Instantly share code, notes, and snippets.

@Qooh0
Last active September 18, 2023 19:06
Show Gist options
  • Save Qooh0/2215ba092b9ea31d0e8894030b1a9fee to your computer and use it in GitHub Desktop.
Save Qooh0/2215ba092b9ea31d0e8894030b1a9fee to your computer and use it in GitHub Desktop.
C-Sharp-Learning

Binary

Hex -> Char

byte data = 0x41;
System.Console.WriteLine((char)data);       // A

Hex array

byte[] data = new byte[2];
data[0] = 0x41;
data[1] = 0x42;
foreach (byte item in data)
{
    System.Console.WriteLine((char)item);   // A B                
}

Invoke

MS Document

Invoke

Static Functions

// public class SubCommands
Type subCommandClass = typeof(SubCommands);
MethodInfo? subCommand = subCommandClass.GetMethod(CapitalizeFirstLetter(firstArgument));
// namespace は省略可
Type subCommandClass = Type.GetType("<namespace>.SubCommands");
MethodInfo? subCommand = subCommandClass.GetMethod(CapitalizeFirstLetter(firstArgument));

Class Instance Functions

// public class SubCommands
SubCommands sc = new SubCommands();
Type subCommandClassInstance = sc.GetType();
MethodInfo? subCommand = subCommandClassInstance.GetMethod(CapitalizeFirstLetter(firstArgument));

not tested

引数を渡す

// Get the ItsMagic method and invoke with a parameter value of 100

MethodInfo magicMethod = magicType.GetMethod("ItsMagic");
object magicValue = magicMethod.Invoke(magicClassObject, new object[]{100});
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Stopwatch

var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000; i++)
{
    Thread.Sleep(1);
}
sw.Stop();

long milliSec = sw.ElapsedMilliseconds;
System.Console.WriteLine($"{milliSec} ms");     // 1163

long ticks = sw.ElapsedTicks;
System.Console.WriteLine($"{ticks} ticks");     // 11557911

他に、restart メソッドとか使いそう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment