如何在不使用像int或dec这样的匈牙利语符号的情况下完成这项工作 [英] How to make this work without using hungarian notations like int or dec for .NET

查看:86
本文介绍了如何在不使用像int或dec这样的匈牙利语符号的情况下完成这项工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在不使用匈牙利语符号(如int或dec)的情况下使下面的代码工作。

我最初使用它但我的导师不喜欢我们使用匈牙利语表示法。所以它适用于匈牙利符号,但现在没有它就行不通。我知道在.NET中,如果使用非匈牙利语代码是为了提高可读性,但这对我来说真的很难。



我尝试过:



I need to make the code below work without using Hungarian Notations such as int or dec.
I did use it at first but my instructor does not like us using the hungarian notation. So it works with hungarian notation but now it doesn't work without it. I know that in .NET the point if using non Hungarian codes is for readability but it really just makes things hard for me.

What I have tried:

Option Strict On
Public Class ChangeCal
    Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles dollars.TextChanged

    End Sub

    Private Sub calculate_Click(sender As Object, e As EventArgs) Handles calculate.Click
        Dim dpaid As Decimal
        Dim dowe As Decimal
        Dim dchangedue As Decimal
        Dim dQuarters As Decimal
        Dim dDimes As Decimal
        Dim dNickels As Decimal
        Dim dPennies As Decimal
        Dim dTempValue As Decimal
        Dim dDollars As Decimal

        dpaid = CDec(Val(paid.Text))
        dowe = CDec(Val(owe.Text))
        dchangedue = dpaid - dowe


        If Not IsNumeric(paid.Text) Then
            MsgBox("Invalid Due Amonut Entry", MsgBoxStyle.Critical)

        End If

        If Not IsNumeric(owe.Text) Then
            MsgBox("Invalid Due Amonut Entry", MsgBoxStyle.Critical)

        End If

        dValue = CInt(dchangedue * 100)

        dDollars = dValue \ 100
        dollars.Text = CType(dDollars, )

        dValue = dValue Mod 100
        dQuarters = dValue \ 25
        quarters.Text = CType(dQuarters, )

        dValue = dValue Mod 25
        dDimes = dValue \ 10
        dimes.Text = CType(dDimes, )

        dValue = dValue Mod 10
        dNickels = dValue \ 5
        nickels.Text = CType(dNickels, )

        dValue = dValue Mod 5
        dPennies = dTempValue
        pennies.Text = CType(dPennies, )

        If dpaid < dowe Then

            MsgBox("You Still Owe=" & Format(decchangedue, "Currency"))
        End If

    End Sub

    Private Sub clear_Click(sender As Object, e As EventArgs) Handles clear.Click
        paid.Clear()
        owe.Clear()
        dollars.Clear()
        quarters.Clear()
        dimes.Clear()
        nickels.Clear()
        pennies.Clear()
    End Sub

    Private Sub xit_Click(sender As Object, e As EventArgs) Handles xit.Click
        Me.Close()
    End Sub
End Class

推荐答案

如果我正确理解你的问题,匈牙利表示法只是为变量命名的一种方式。如果命名没有冲突并且变量被正确使用,则代码将无论符号如何都可以工作(匈牙利语,CamelCase,...)。



所以代码没有工作与符号没有任何关系,但你如何使用定义的变量。



你没有说明你的意思代码不起作用,但是一眼就看出你在这里错误地命名了变量



If I understand your question correctly, Hungarian notation is just a way of giving names to your variables. If the naming has no conflicts and variables are properly used, the code will work regardless of the notation (Hungarian, CamelCase,...).

So the code not working does not have anything to do with the notation, but how you use the defined variables.

You didn't specify what you mean with "code doesn't work", but at a glance it looks like you have falsely named variable here

MsgBox("You Still Owe=" & Format(decchangedue, "Currency"))



在声明中,您已将名称声明为 dchangedue

如果是这样,编译器应该向您显示有关情况的错误。


In the declarations you have declared the name as dchangedue
If that is true, the compiler should show you an error about the situation.


引用:

所以它适用于匈牙利表示法但现在没有它就无法工作。

So it works with hungarian notation but now it doesn't work without it.



如何用匈牙利语编写工作代码表示法并且无法将变量名称更改为删除匈牙利表示法部分?

我只看到两种可能性:

- 变量名称更改在您的代码中不一致。

- 变量名称更改会导致名称冲突(2个不同的名称,不同的名称最终都是相同的名称)。



但是没有看到非工作代码,它很难分辨。


How is it possible to write working code with Hungarian notation and be unable to change variables names to remove the Hungarian notation part ?
I see only 2 possibilities:
- Either the variables names changes are not consistent across your code.
- Either the variables names changes are making names collisions (2 different things with different names end up with same name).

But without seeing the 'non working code', it is difficult to tell.


这篇关于如何在不使用像int或dec这样的匈牙利语符号的情况下完成这项工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆