c#局部变量命名指南

本文关键字:局部变量 | 更新日期: 2023-09-27 18:07:50

关于在接受同名参数的c#方法中命名局部变量的问题请参阅下面的代码

 private int DoSomething(string activationCode)
    {
        ...
        int ??WhatNameToChooseHere?? = Convert.ToInt32(activationCode);
        ...
    }

在上述场景中应用什么策略是好的

注意:方法参数和局部变量只有类型不同

c#局部变量命名指南

你不能那样做。正确的方法是使用不同的名称来命名变量。

private int DoSomething(string activationCodeStoredInStringAndPassedAsAnArgument)    {
    int activationCodeThatDeclaredAsAnIntegerToStoreTheValueConvertedFromString = Convert.ToInt32(activationCodeStoredInStringAndPassedAsAnArgument);
}