• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

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

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.

        [System.Xml.Serialization.XmlIgnore()]

in

    public class Schedule
    {
        public struct Interval
        {
            public int length;
            public string unit;
        }
        [System.Xml.Serialization.XmlIgnore()]
        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?

Thanks!
0
freezegravity
Asked:
freezegravity
1 Solution
 
Malik1947Commented:
look at this article
http://msdn2.microsoft.com/en-us/library/a3hd7ste(vs.80).aspx

the square brackets seem to be referring to a "pointer" or a token to something else in the application.
0
 
JimBrandleyCommented:
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.

Jim
0
 
Liquid90605Commented:
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.
0
 
SolutionsCSCommented:
Liquid90605:Perfect answer go with it.
0
 
freezegravityAuthor Commented:
After reading the answer, I still had a few questions. However, I looked them up and the answer is correct.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now