Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# class definition unknown

Tags:

c#

I am looking through some C# code and I am seeing something I cannot figure out near the class definition. Here is a sample of what I am seeing.

[MethodImpl(MethodImplOptions.Synchronized)]
public void AddTag(RTag tag)
{
    this.tags.Add(tag)
}

What the heck is the first line doing or stating? I have not been able to track it down in any of my reference books.

Thanks!

like image 520
twamn Avatar asked Jan 24 '23 00:01

twamn


1 Answers

The first line is an attribute, i.e. meta data attached to the method.

The MethodImplAttribute specifies the details of how a method is implemented. In particular, MethodImplOptions.Synchronized

Specifies that the method can be executed by only one thread at a time. Static methods lock on the type, whereas instance methods lock on the instance. Only one thread can execute in any of the instance functions, and only one thread can execute in any of a class's static functions.

like image 114
dtb Avatar answered Jan 27 '23 02:01

dtb