C#与此代码混淆 [英] C# confusion with this code

查看:127
本文介绍了C#与此代码混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



this is my code

//part of the idle stuff
        [StructLayout(LayoutKind.Sequential)]
        struct LASTINPUTINFO
        {
            public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));

            [MarshalAs(UnmanagedType.U4)]
            public UInt32 cbSize;
            [MarshalAs(UnmanagedType.U4)]
            public UInt32 dwTime;
        }

uint idleTime = 0;
            LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();

            //int y = Convert.ToInt32(lastInputInfo);
            uint y = Convert.ToUInt32(lastInputInfo);
            lastInputInfo.cbSize = Marshal.SizeOf(y);
            lastInputInfo.dwTime = 0;</pre>



i顺便使用这两种方法,因为它无法弥补它的意思,这是我的错误





< code>错误1无法将类型'int'隐式转换为'uint'。存在显式转换(您是否缺少演员表?)Z:\ UnHidden\UnHidden\Form1.cs 48 36 UnHidden< / code>



和i每个转换代码得到相同的错误,有人可以告诉我发生了什么以及如何解决这个问题?


i used both those methods by the way because it can't make up its mind and this is my error


<code>Error 1 Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?) Z:\UnHidden\UnHidden\Form1.cs 48 36 UnHidden</code>

and i get the same error with each of those convert codes, can some one please tell me whats happening and how i can possibly fix this?

推荐答案

错误非常明显,并告诉你该怎么做:要么将定义更改为Int32,要么将值转换为UInt32:

The error is pretty explicit, and does tell you what to do: either change the definition to Int32, or cast the values to UInt32:
lastInputInfo.cbSize = (UInt32) Marshal.SizeOf(y);


这篇关于C#与此代码混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆