Class or function variable?
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#)
精彩评论