1
\$\begingroup\$

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 
ferada
11.4k25 silver badges65 bronze badges
asked Dec 3, 2014 at 13:36
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Would you mind to add a little bit of context about what this method should do ? \$\endgroup\$ Commented Dec 3, 2014 at 13:41

1 Answer 1

1
\$\begingroup\$

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
answered Dec 3, 2014 at 13:47
\$\endgroup\$
6
  • \$\begingroup\$ 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" }. \$\endgroup\$ Commented Dec 3, 2014 at 13:49
  • \$\begingroup\$ I agree with the problem of method name. thx \$\endgroup\$ Commented Dec 3, 2014 at 13:50
  • \$\begingroup\$ @Abbas I would agree, about some reason..., if the List had been declared outside of the method. \$\endgroup\$ Commented Dec 3, 2014 at 13:51
  • \$\begingroup\$ The list is not required and is a big part of the reason I'm asking for a better way. \$\endgroup\$ Commented Dec 3, 2014 at 13:52
  • \$\begingroup\$ Then you should indeed never use a List and use the solution @Heslacher provided. \$\endgroup\$ Commented Dec 3, 2014 at 14:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.