小编Ken*_*Kin的帖子

如何将整个文件夹添加到zip存档中

我尝试了一下zip.AddDirectory,但是我不知道如何将整个文件夹导入到存档中(使用DotNetZip)。

想要这样:

在此处输入图片说明

但是这个:

在此处输入图片说明

c# dotnetzip

3
推荐指数
1
解决办法
2551
查看次数

读Registry_binary并转换为字符串

我一直在寻找最后2个小时,而我实际上一直在寻找愚蠢的.

我试图读取Registry_binary值并将其转换为字符串.我尝试了一些我在网上找到的东西(包括一些stackoverflow帖子),但似乎我无法让它工作:

class Class1 {
    RegistryKey RegKey;
    String keys;

    static void Main() {
        Class1 c=new Class1();
        c.initialize();
    }

    void initialize() {
        RegKey=Registry.LocalMachine.OpenSubKey("the location", true);
        var bytearray=Converter<RegKey.GetValue("key"), String[keys]>;
        Console.WriteLine(bytearray);
        System.Threading.Thread.Sleep(5000);
    }
}
Run Code Online (Sandbox Code Playgroud)

我也试过用:

keys=keys+BitConverter.ToString(System.byte[RegKey.GetValue("key")]);
Run Code Online (Sandbox Code Playgroud)

根据要求:

RegKey=Registry.LocalMachine.OpenSubKey("Software\\MXstudios\\riseingtesharts", true);
keys=RegKey.GetValue("key");
Run Code Online (Sandbox Code Playgroud)

这将输出 System.Bytes[]

c# tostring registrykey

3
推荐指数
1
解决办法
7406
查看次数

如何锁定并强制用户重新输入 Windows 密码?

我想锁定当前操作用户的访问,就好像该用户

单击“开始”→指向“关机”→单击“锁定”

在 C# 中如何做到这一点?

c# windows windows-shell user-accounts

3
推荐指数
1
解决办法
418
查看次数

如何在数组中插入值,保留顺序?

我有一个字符串数组,我想在中心的某处添加一个新值,但不知道如何执行此操作.任何人都可以为我制作这种方法吗?

void AddValueToArray(String ValueToAdd, String AddAfter, ref String[] theArray) {
    // Make this Value the first value
    if(String.IsNullOrEmpty(AddAfter)) {
        theArray[0]=ValueToAdd; // WRONG: This replaces the first Val, want to Add a new String 
        return;
    }

    for(int i=0; i<theArray.Length; i++) {
        if(theArray[i]==AddAfter) {
            theArray[i++]=ValueToAdd; // WRONG: Again replaces, want to Add a new String 
            return;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# arrays

2
推荐指数
1
解决办法
6432
查看次数

在c#中记录击键时键入特殊字符时显示的双字符

我有一个应用程序,登录任何用户按下,但是当我按下特殊字符,如´a,得到á,我得到的´´a; 同样的事情,当我想得到à,然后我得到``a,所以所有特殊字符输入两次,然后常规字符输入后.

我一直在搜索,真的找不到任何东西.但我注意到问题出在ToAscii方法中,没有正确输入字符.

public string GetString(IntPtr lParam, int vCode)
{
    try
    {
        bool shift = Keys.Shift == Control.ModifierKeys || Console.CapsLock;

        string value = ""; 

        KeyboardHookStruct MyKeyboardHookStruct = 
            (KeyboardHookStruct)Marshal.PtrToStructure(
                lParam, typeof(KeyboardHookStruct));

        byte[] keyState = new byte[256];
        byte[] inBuffer = new byte[2];

        DllClass.GetKeyboardState(keyState);

        var ascii=
            DllClass.ToAscii(
                MyKeyboardHookStruct.vkCode, 
                MyKeyboardHookStruct.scanCode, 
                keyState, inBuffer, MyKeyboardHookStruct.flags
                );

        if (ascii == 1)
        {
            char key = (char)inBuffer[0];

            if ((shift) && Char.IsLetter(key))
                key = Char.ToUpper(key); …
Run Code Online (Sandbox Code Playgroud)

c# logging keycode character-encoding winforms

2
推荐指数
1
解决办法
2027
查看次数

为什么这种方法会导致异常超载?

我已经看过很多关于通过更改其返回类型来重载方法的帖子,但是,理想情况下,以下程序应该可以正常工作,因为iinteger类型的变量只能包含整数值.

因此,它理想情况下应该调用函数int print(int a)函数,甚至不看函数,float print(int a)因为它返回一个浮点值,而且main(),我使用了一个整数变量来保存方法返回的值,而整数变量永远不能保持浮点数价值..

以下代码演示了它→

class temp 
{
    public float print(int a) 
    {
        int l=12.55;
        return l;
    }

    public int print(int a) 
    {
        int p=5;
        return p;
    }
}

class Program 
{
    static void Main(string[] args) 
    {
        temp t=new temp();
        int i=t.print(10);
        A.Read();
    }
}
Run Code Online (Sandbox Code Playgroud)

在其他情况下,我做这样的事情→

class temp 
{
    public float print(int a) 
    {
        int l=12.55;
        return l;
    }

    public int print(int a) 
    {
        int p=5;
        return p;
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# oop overloading

2
推荐指数
2
解决办法
175
查看次数

数组类型在哪里?

如果我们想制作一个特定类型的数组类型,使用起来没有问题MakeArrayType(),例如数组char

typeof(char).MakeArrayType()
Run Code Online (Sandbox Code Playgroud)

当然用起来更直观typeof(char[])

Assembly类型的属性告诉我们该类型所在的程序集是什么。

因此,以下代码应该是在程序集中查找类型的合理示例:

var chars=new[] { '\x20' };
var typeofCharArray=chars.GetType();
var assembly=typeofCharArray.Assembly;
var doesContain=assembly.GetTypes().Contains(typeofCharArray);
Run Code Online (Sandbox Code Playgroud)

doesContain说它不是,它是false。无论数组类型是来自MakeArrayType()or typeof(),还是实例的 ,都会发生这种情况GetType

怀疑它是否被转发到我从Assembly.GetTypes读取的其他程序集。我尝试过:

var assemblyContainsTypeOfCharArray=(
        from it in AppDomain.CurrentDomain.GetAssemblies()
        let types=it.GetTypes()
        where types.Contains(typeof(char[]))
        select it).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

有趣的assemblyContainsTypeOfCharArraynull

数组类型在哪里?

c# clr jit .net-assembly

2
推荐指数
1
解决办法
234
查看次数

如何在C#中编组一个IntPtr的异常

我想Exception在非托管C程序集中保留指向托管对象的指针.

我尝试了很多方法.这是我发现的唯一通过我的初步测试的人.

有没有更好的办法?

我真正想做的是处理ExceptionWrapper构造函数和析构函数中的alloc和free方法,但是struct不能有构造函数或析构函数.

编辑:回复:为什么我想这样:

我的C结构有一个函数指针,该指针由一个托管委托作为非托管函数指针封送.受管代理使用外部设备执行一些复杂的测量,在这些测量期间可能会出现异常.我想跟踪发生的最后一个及其堆栈跟踪.现在,我只保存异常消息.

我应该指出托管委托不知道它与C DLL交互.

public class MyClass {
    private IntPtr _LastErrorPtr;

    private struct ExceptionWrapper
    {
        public Exception Exception { get; set; }
    }

    public Exception LastError
    {
        get
        {
            if (_LastErrorPtr == IntPtr.Zero) return null;
            var wrapper = (ExceptionWrapper)Marshal.PtrToStructure(_LastErrorPtr, typeof(ExceptionWrapper));
            return wrapper.Exception;
        }
        set
        {
            if (_LastErrorPtr == IntPtr.Zero)
            {
                _LastErrorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ExceptionWrapper)));
                if (_LastErrorPtr == IntPtr.Zero) throw new Exception();
            }

            var wrapper = new ExceptionWrapper();
            wrapper.Exception = value;
            Marshal.StructureToPtr(wrapper, _LastErrorPtr, true); …
Run Code Online (Sandbox Code Playgroud)

.net c c# clr marshalling

1
推荐指数
1
解决办法
1131
查看次数

如何订购2个不同的清单?

我有Step班级和AutoStep班级

class Step {
    int StepNumber;
}

class AutoStep {
    int StepNumber;
}
Run Code Online (Sandbox Code Playgroud)

它们不是从任何类继承而且不能从任何类继承.

我必须按StepNumber对它们进行排序,并根据其类型(StepAutoStep)调用特定方法

我怎样才能做到这一点?

c#

1
推荐指数
1
解决办法
120
查看次数

Linq Where声明表现缓慢

我有一个ListObjects(约10万),即必须以产生在迭代Dictionary.但是代码执行速度非常慢,特别是在一行上

public class Item{
        public int ID;
        public int Secondary_ID;
        public string Text;
        public int Number;
}
Run Code Online (Sandbox Code Playgroud)

数据看起来像(100k行)

ID  | Secondary_ID |      Text       | Number
1   |    1         | "something"     | 3
1   |    1         | "something else"| 7
1   |    1         | "something1"    | 4
1   |    2         | "something2"    | 344
2   |    3         | "something3"    | 74
2   |    3         | "something4"    | 1
Run Code Online (Sandbox Code Playgroud)

我希望它在完成后看起来像这样.(任何收藏都要诚实)

 Dictionary<int, string> 

Key             | Value
(secondary_ID) …
Run Code Online (Sandbox Code Playgroud)

c# linq

1
推荐指数
2
解决办法
3951
查看次数