开发者

Class or function variable?

开发者 https://www.devze.com 2023-02-19 11:10 出处:网络
As a means of speeding up my program, I have it look through a list of words and see if a certain string contains any of those words, in which case it can skip following code and move on.This happens

As a means of speeding up my program, I have it look through a list of words and see if a certain string contains any of those words, in which case it can skip following code and move on. This happens thousands of times.

I'm in the process of cleaning up my code, and where before I had my list defined as a private string[], it makes more sense visually to have it inside my new ContainsWordsToSkip() method. However, unless I'm mistaken, string[] wordsToSkip would have to be reallocated in memory with each call and it would be be开发者_StackOverflow社区tter leave it as a class member.

Is this correct?


Yes, it should be a class member. Additionally, if it's not changing between instances, it should be static (all based on the assumption that your code looks like C#)

0

精彩评论

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