Ace Frahm Ace Frahm - 4 months ago 12
C# Question

Are These Square Brackets Indicating An Indexer?

public class Task : IBusinessEntity
{
public Task () {}

[PrimaryKey, AutoIncrement]
public int ID { get; set; }

public string Name { get; set; }
public string Notes { get; set; }
public bool Done { get; set; }
}


Is the
[PrimaryKey, AutoIncrement]
an indexer in C#?

This code is made to work with SQLlite-NET.

Would the index be defined in
IBusinessEntity
or whatever that inherits from?

Answer

They are called attributes.

Here is the documentation from Microsoft, and here is a tutorial about them.

You can declare them at a class level like this (code from MSDN tutorial):

[AttributeUsage(AttributeTargets.All)]
public class HelpAttribute : System.Attribute 

Or at a method-level:

[WebMethod]
public void SomeWebMethod([System.Web.Services.WebMethod(
   Description="Describe what your method does here.")])

Or, at the member-level like you have already declared above. Happy coding!

Comments