比较两个非数字值,在 ASP.NET/VB.NET 中选择较低值

发布于 2024-12-28 09:55:28 字数 596 浏览 4 评论 0原文

我正在更新我的雇主(一所大学)使用的我编写的应用程序,以允许学生注册他们想要的宿舍。

我正在开发一项新功能,允许学生与另一名学生“合作”——这样,当其中一个学生注册一个房间时,另一个学生也会注册。

现在,假设我们有 John Doe 和 James Doe,他们相互合作进行房间登记。学生根据当前班级水平错开的时间。我需要一种方法来确定(没有十亿个 IF..THEN 语句)哪个学生的班级水平较低。班级级别的值为 FR、SO、JR、SR、5SR(从最低级到最高级)。

在上面的示例中,John Doe 可能是 FR,而 James Doe 可能是 SR。在允许 FR 注册之前,詹姆斯和约翰都不应被允许注册 - 因为那是合伙企业的“基础”级别。

本质上我想做一些类似的事情:

IF John_Doe_Class_Level < James_Doe_Class_Level Then
   Partnership_Class_Level = John_Doe_Class_Level
Else
   Partnernship_Class_Level = James_Doe_Class_Level
End If

知道如何有效地完成这个任务吗?

I am updating an application I've written used by my employer, a University, to allow students to register for their desired residence hall.

I'm working on a new feature that will allow students to "partner" with another student - so that when one or the other registers for a room, the other student will be registered as well.

Now, let us say we have John Doe and James Doe - and they partner with each other for room registration. The time when students is staggered based on their current class level. I need a way to determine (without a billion IF..THEN statements) which student has the lower class level. The values for class level are FR, SO, JR, SR, 5SR (from most junior to most senior).

In the above example, John Doe might be a FR while James Doe may be a SR. Neither James nor John should be allowed to register until FR's are allowed to register - since that is the partnerships "base" class level.

Essentially I want to do something like:

IF John_Doe_Class_Level < James_Doe_Class_Level Then
   Partnership_Class_Level = John_Doe_Class_Level
Else
   Partnernship_Class_Level = James_Doe_Class_Level
End If

Any idea how to accomplish this effectively?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

找个人就嫁了吧 2025-01-04 09:55:28

您在哪里定义班级级别?如果它在代码中,请使用具有关联数值的枚举。

Public Enum ClassLevel As Integer
    FR = 0
    SO = 1
    JR = 2
End Enum

Public Class Student
    Public Property Name As String
    Public Property Level As ClassLevel
End Class

Public Sub TestIt(ByVal studentA As Student, ByVal studentB As Student)
    If studentA.Level > studentB.Level Then
        ' dostuff
    End If
End Sub

Where do you define your class levels? If it is in the code, use enums with associated numeric values.

Public Enum ClassLevel As Integer
    FR = 0
    SO = 1
    JR = 2
End Enum

Public Class Student
    Public Property Name As String
    Public Property Level As ClassLevel
End Class

Public Sub TestIt(ByVal studentA As Student, ByVal studentB As Student)
    If studentA.Level > studentB.Level Then
        ' dostuff
    End If
End Sub
空城仅有旧梦在 2025-01-04 09:55:28

我知道我显然遗漏了一些东西,但是如果您将这些类级别分配给枚举,为什么上面的方法不起作用?


public enum ClassLevel
{
  FR=1, 
  SO=2, 
  JR=2,
  SR=3,  
  5SR=4
}

etc

IF John_Doe.ClassLevel < JamesDoe.Class_Level Then
   Partnership.Class_Level = John_Doe.ClassLevel
Else
   Partnernship.Class_Level = James_Doe.ClassLevel
End If

I know I'm clearly missing something, but if you assign these class levels to an enum, why wouldn't the above work?


public enum ClassLevel
{
  FR=1, 
  SO=2, 
  JR=2,
  SR=3,  
  5SR=4
}

etc

IF John_Doe.ClassLevel < JamesDoe.Class_Level Then
   Partnership.Class_Level = John_Doe.ClassLevel
Else
   Partnernship.Class_Level = James_Doe.ClassLevel
End If

戏剧牡丹亭 2025-01-04 09:55:28

我将通过返回数字的函数运行这些值,然后将这些值相互比较。像...

IF numericClassLevel(John_Doe_Class_Level) < numericClassLevel(John_Doe_Class_Level) Then   
    Partnership_Class_Level = John_Doe_Class_Level
Else
    Partnernship_Class_Level = James_Doe_Class_Level
End If

public function numericClassLevel(strClassLevel) as integer
    select case strLevel
        case "FR"
            return 1
        etc.
    end select
end function

I would run the values through function that returns a number then compare those values to each other. Something like...

IF numericClassLevel(John_Doe_Class_Level) < numericClassLevel(John_Doe_Class_Level) Then   
    Partnership_Class_Level = John_Doe_Class_Level
Else
    Partnernship_Class_Level = James_Doe_Class_Level
End If

public function numericClassLevel(strClassLevel) as integer
    select case strLevel
        case "FR"
            return 1
        etc.
    end select
end function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文