thirteenbinary
thirteenbinary
CC#
Created by thirteenbinary on 4/3/2023 in #help
❔ Pointer Issue.
My pathetic code:
c#
unsafe class Test
{
static void Main()
{
int a = 1; int b = 2;
int* x = &a, y = &b;
Console.WriteLine($"{*x} and {*y}");
Swap(out x, out y);
Console.WriteLine($"{*x} and {*y}");
}

static void Swap(out int* a, out int* b)
{
long x = (long)a;
long y = (long)b;
x ^= y ^= x ^= y;
a = (int*)x; b = (int*)y;
}
}
c#
unsafe class Test
{
static void Main()
{
int a = 1; int b = 2;
int* x = &a, y = &b;
Console.WriteLine($"{*x} and {*y}");
Swap(out x, out y);
Console.WriteLine($"{*x} and {*y}");
}

static void Swap(out int* a, out int* b)
{
long x = (long)a;
long y = (long)b;
x ^= y ^= x ^= y;
a = (int*)x; b = (int*)y;
}
}
Terrible error:
Error CS0269 Use of unassigned out parameter 'a' ConsoleApp1
Error CS0269 Use of unassigned out parameter 'b' ConsoleApp1
Error CS0269 Use of unassigned out parameter 'a' ConsoleApp1
Error CS0269 Use of unassigned out parameter 'b' ConsoleApp1
Why?
28 replies
CC#
Created by thirteenbinary on 3/30/2023 in #help
❔ How to calculate event expression?
like
c#
var result = a+b-c+d-c+d-b+a;
c#
var result = a+b-c+d-c+d-b+a;
a,b,c,d are all events, and each of them contains more than one method. So what is result like?
11 replies
CC#
Created by thirteenbinary on 3/27/2023 in #help
❔ The ``Instance`` value in ``BindingFlags``
I use the GetMethod and find the Instance required if I need to get any method. But truly the method is not an instance and it is just a method. So why?
4 replies
CC#
Created by thirteenbinary on 3/19/2023 in #help
❔ What of use is the keyword "event"
The essence of the event field is just an object of delegate type which will invoke embedded methods when it is invoked like a method, coding below is also ok:
c#
using System;

class A
{
public delegate void F(int x, int y);
static public /*Event*/ F Event;

public static void Hi()
{
Event(1, 2);
}
}

class B
{
internal void Print(int x,int y)
{
Console.WriteLine(x + y);
}
}

public class Test
{
static void Main()
{
B suck = new B();
A.Event += suck.Print;
A.F x = new A.F(suck.Print);
A.Hi();
x(1, 2);
}
}
c#
using System;

class A
{
public delegate void F(int x, int y);
static public /*Event*/ F Event;

public static void Hi()
{
Event(1, 2);
}
}

class B
{
internal void Print(int x,int y)
{
Console.WriteLine(x + y);
}
}

public class Test
{
static void Main()
{
B suck = new B();
A.Event += suck.Print;
A.F x = new A.F(suck.Print);
A.Hi();
x(1, 2);
}
}
So the question comes.
12 replies
CC#
Created by thirteenbinary on 3/18/2023 in #help
❔ What of use is the identifier for the delegate?
I do think
public delegate void NumManipulationHandler(string state);
public delegate void NumManipulationHandler(string state);
can be modified into
public delegate void NumManipulationHandler(string);
public delegate void NumManipulationHandler(string);
but it hates to do it.
9 replies
CC#
Created by thirteenbinary on 3/15/2023 in #help
❔ Why I need to specify the assembly while I was reflecting DataTable?
Why do I have to code like
Console.WriteLine(Type.GetType("System.Data.DataTable, System.Data.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
Console.WriteLine(Type.GetType("System.Data.DataTable, System.Data.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
but
Console.WriteLine(Type.GetType("System.Data.DataTable"));
Console.WriteLine(Type.GetType("System.Data.DataTable"));
32 replies