C#无法从(内部结构)访问代码 [英] C# can't Access Code from (internal struct)

查看:54
本文介绍了C#无法从(内部结构)访问代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码


this is my code


public Form1()
 {
     LASTINPUTINFO lastInPut = new LASTINPUTINFO();
     lastInPut.cbSize = (uint)
       System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);

     InitializeComponent();
 }







and

[DllImport("User32.dll")]
private static extern bool
        GetLastInputInfo(ref LASTINPUTINFO plii);

internal struct LASTINPUTINFO
{
    public uint cbSize;

    public uint dwTime;
}



这是我试图访问dwTime



and this is me trying to access the dwTime

private void Form1_Load(object sender, EventArgs e)
   {
    
 this.Text = dwTime.toString();
   }



但是它显然不起作用,我应该可以访问它,因为我将其公开了,为什么?



but it obously doesn''t work, i should be able to access it because i made it public, why??

推荐答案

不,不能访问公共属性没有指定对象.如果不告诉编译器"dwTime"的来源,它将无法找到它.

No, a public property cannot be accessed without specifying the object. Without telling the compiler where your "dwTime" is coming from, it will not be able to find it.

lastInPut.dwTime


private LASTINPUTINFO lastInPut;
public Form1()
       {
           lastInPut = new LASTINPUTINFO();
           lastInPut.cbSize = (uint)
             System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);

           InitializeComponent();
       }


再试一次.

您可能想去图书馆,为初学者买一本好书.声明变量并不难,但是在没有基础知识的情况下继续做更复杂的事情也不是一个好主意.


Try again.

You might want to head to the library and get a good book for beginners; declaring variables is not difficult, but it''s not a good idea to continue doing more complexer things without the basics.


这篇关于C#无法从(内部结构)访问代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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