We help IT Professionals succeed at work.

What do the brackets mean in c#? I mean these" [ ] when they are not referencing arrays

Medium Priority
Last Modified: 2012-05-05
I am trying to read some C# code that someone else has written.

I am coming across this line and am having trouble understanding it.



    public class Schedule
        public struct Interval
            public int length;
            public string unit;
        public bool intervalSpecified;
        public Interval interval;

I am weak at Serialization, but that is another issue. I was thinking that [] was only an array symbol, but System.Xml.Serialization.XmlIgnore doesn't seem to be part of any array. If I remove the [], then I get a "Invalid Token" error. So, essentially, what does the [] do?

Watch Question

look at this article

the square brackets seem to be referring to a "pointer" or a token to something else in the application.
Top Expert 2007

Statements like that above methods, properties or members are called Attributes. In this case, it acts like qualifier, and will cause a serializer to ignore the boolean member called intervalSpecified. You can also define and create your own custom attributes that can be very useful when using reflection into your own assemblies.

That is called an Attribute, that one is specifically an XML Serialization Attribute. Those Markers are used at specify certain things. That attribute in particular is used to tell a the program at runtime Not To Include That Data Member In Serialization.
Liquid90605:Perfect answer go with it.


After reading the answer, I still had a few questions. However, I looked them up and the answer is correct.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.