Click here to Skip to main content
15,849,328 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello guys,

I have the following code.

C#
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
C#
if (length == 4 && values[1] == "VNUM") "i."
then no variable from Item appears.

Do you know how to help me?
Posted
Updated 9-Nov-14 8:44am
v4
Comments
Afzaal Ahmad Zeeshan 9-Nov-14 13:42pm    
Does it throw any error?
IceTrailer 9-Nov-14 13:43pm    
No, I only can't access the vars from struct Item..
Afzaal Ahmad Zeeshan 9-Nov-14 13:44pm    
How does it tell you that you can't access the struct?
IceTrailer 9-Nov-14 13:47pm    
IntelliSense of Visual Studio 2013 only displays following possibilities
- Equals
- GetHashCode
- GetType
- ToString


Uh, and this error appears if I use i.iVnum = 1;
The access at "ClientExtraction.Functions.Item.iVnum" is because of the safety level not possible
Sergey Alexandrovich Kryukov 9-Nov-14 13:50pm    
It's not "vars". Do you know what a member is?
—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
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 9-Nov-14 13:52pm    
Sir, you needed to write public not private (in the first paragraph, last word). :-)

He has already set it to private (by He I mean .NET of course).
Sergey Alexandrovich Kryukov 9-Nov-14 13:57pm    
Thank you very much, I fixed it.
It should be internal or public; internal is usually better. :-)
—SA
Afzaal Ahmad Zeeshan 9-Nov-14 13:59pm    
I am not that much good in these things, I usually set everything to public ;-)

But since you've mentioned I will give it a read now. :-)

..and yeah, you're welcome ;)
Sergey Alexandrovich Kryukov 9-Nov-14 14:40pm    
Isn't that trivial: internal is like public, only not giving access outside of declaring assembly?
And I believe that the access should be as constrained as possible.
—SA
IceTrailer 9-Nov-14 13:53pm    
Thank you for posting your solution. It works.

Sorry, I missed out to look if the error could be in struct Item.
In your comment you added the most valuable piece of information to the question.

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


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.

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


Now they will be accessible by the code. Every member or property or function that you set to be public can be accessed. You can learn more on these, here on MSDN[^].
 
Share this answer
 
v2
Comments
IceTrailer 9-Nov-14 13:58pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900