开发者

Couple of VB.Net lines in C#

开发者 https://www.devze.com 2023-01-31 22:51 出处:网络
I am converting a project from VB.Net, and I have a few lines that I am unable to convert propperly.

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é


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] 
0

精彩评论

暂无评论...
验证码 换一张
取 消