如何从同一个类访问struct? [英] How to access struct from same class?

查看:100
本文介绍了如何从同一个类访问struct?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有以下代码。



Hello guys,

I have the following code.

struct Item
        {
            // VNUM
            int iVnum;
            int iPrice;

            // NAME
            string iStrName;

            // INDEX
            int iEqSlot;
            int iSPCardID;
            int iFairyID;

            // TYPE
            int iClass;

            // FLAG
            int iMale;
            int iFemale;

            int iSellable;
            int iDropable;
            int iTradable;

            // DATA
            int iLvReq;
            int iJlDef;
            int iCDef;
            int iFDef;
            int iMDef;
            int iDodge;
            int iJlReq;
            int iRepReq;
            int iDmgMin;
            int iDmgMax;
            int iHitrate;
            int iCritChance;
            int iCritDmg;

            int iResF;
            int iResW;
            int iResL;
            int iResS;

        }

       public static void readDatFile(string path)
        {
            Item i;
            
            using (StreamReader sr = new StreamReader(path, Encoding.Default, true))
            {
                string line;
                string[] values;
                int length;

                while ((line = sr.ReadLine()) != null)
                {
                    values = line.Split('\t');
                    length = values.Length;
                    
                        if (length == 4 && values[1] == "VNUM")
                        {
                            i.iVnum = 1;
                        }

                }
            }

        }



但为什么我无法访问声明的项目我?

如果我输入


But why can't I access the declared Item i ?
if I type in at

if (length == 4 && values[1] == "VNUM") "i."

然后没有来自Item的变量。



你知道如何帮助我吗?

then no variable from Item appears.

Do you know how to help me?

推荐答案

这是因为 iVum 是私有的(默认);可以访问,它应该是内部的或公共的。



您的代码和帖子看起来好像您在阅读语言和平台手册之前尝试编写某些应用程序。这种做法适得其反。



-SA
This is because iVum is private (default); to be accessible, it should be internal or public.

Your code and post look as if you tried to write some application before reading a manual on the language and platform. Such approach is counter-productive.

—SA


在评论中你添加了最多这个问题的宝贵信息。



In your comment you added the most valuable piece of information to the question.

引用:

Visual Studio的智能感知2013只显示以下可能性

- 等于

- GetHashCode

- GetType

- ToString

IntelliSense of Visual Studio 2013 only displays following possibilities
- Equals
- GetHashCode
- GetType
- ToString





这是因为结构的成员(属性)被设置为默认的 private 访问者(如果我是这些公共的,私人的被称为别的东西我在这个不好的方面)。您需要将它们设置为 public 。以便访问它们的一切。这意味着Visual Studio的IntelliSense无法获取您要使用的任何成员或属性,因此只提供了4个选项,这些选项是(AFAIK)继承自 System.Object



他们真的非常冗长,但我可以给你看一个例子。





This is because the members (properties) of the struct are set to the default private accessor (mock me if these public, private are called something else I am not good in this one). You need to set them to public. So that everything that access them. This means that Visual Studio's IntelliSense was not able to fetch any of the members or properties for you to use and thus only 4 options were provided, which are (AFAIK) inherited from System.Object.

They are really very lengthy, but I can show you an example.

// set a public with them
public int iVnum;
public int iPrice;





现在可以通过代码访问它们。您可以访问您设置为公开的每个成员或财产或职能。您可以在这里了解更多信息,在MSDN上 [ ^ ]。


这篇关于如何从同一个类访问struct?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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