René Sackers
René Sackers

Reputation: 2635

Couple of VB.Net lines in C#

I am converting a project from VB.Net, and I have a few lines that I am unable to convert propperly.

System.Runtime.Caching.MemoryCache.Default(Me.Name)

In this line, I understand that "Me.Name" has to be "this.Name", but the error is "Non-invocable member 'System.Runtime.Caching.MemoryCache.Default' cannot be used like a method.".

I have correctly added System.Runtime.Caching to References

Also return new string[];. I have no idea how to convert this.

Thanks in advance,
René

Upvotes: 1

Views: 177

Answers (1)

Ani
Ani

Reputation: 113402

It appears you want to call an indexer (sometimes called the Item property). C# uses square-brackets [] for this purpose.

System.Runtime.Caching.MemoryCache.Default[this.Name]

I would suggest two other changes:

  1. If there's no ambiguity, you can leave out the this.
  2. With the appropriate using directive (using System.Runtime.Caching;), the type doesn't have to be fully qualified.

 MemoryCache.Default[Name] 

Upvotes: 3

Related Questions