Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Each letter represent a category. Example the group with "M" Code is greater Than "I" and "C" group. "F" is the higher group

Here is what I did but I wonder if there is a better way to do it.

 Private Function CompareCode(ByVal code As String, ByVal otherCode As String) As Boolean
    Dim orderedCode As New List(Of String)
    orderedCode.Add("I")
    orderedCode.Add("C")
    orderedCode.Add("M")
    orderedCode.Add("F")

    Return orderedCode.IndexOf(code) < orderedCode.IndexOf(otherCode)

End Function   
share|improve this question
1  
Would you mind to add a little bit of context about what this method should do ? – Heslacher Dec 3 '14 at 13:41
up vote 1 down vote accepted

Naming

The name CompareCode does not express ll what this method is doing. Try to name it more meaningful.

General

You don't need a List(Of String) here. Add a private const string like

Private Const orderedCode As String = "ICMF"
Private Function CompareCode(ByVal code As String, ByVal otherCode As String) As Boolean
    Return orderedCode.IndexOf(code) < orderedCode.IndexOf(otherCode)
End Function
share|improve this answer
    
If for some reason he must use a List(Of String), this might be cleaner: Dim orderedCode As New List(Of String) From { "I", "C", "M", "F" }. – Abbas Dec 3 '14 at 13:49
    
I agree with the problem of method name. thx – Jeanseb Dec 3 '14 at 13:50
    
@Abbas I would agree, about some reason..., if the List had been declared outside of the method. – Heslacher Dec 3 '14 at 13:51
    
The list is not required and is a big part of the reason I'm asking for a better way. – Jeanseb Dec 3 '14 at 13:52
    
Then you should indeed never use a List and use the solution @Heslacher provided. – Abbas Dec 3 '14 at 14:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.