【问题标题】:Cannot implicitly convert type 'string' to 'var'无法将类型“字符串”隐式转换为“变量”
【发布时间】:2014-09-22 22:42:22
【问题描述】:

我收到此错误:

无法将类型'string'隐式转换为'var'

using System.Web.Helpers;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    
        var ss = Crypto.HashPassword("1234");

        Response.Write(ss);
    }
}

【问题讨论】:

  • 尝试将ss 类型替换为System.String - 会发生什么?
  • 现在可以正常工作了。它转换为哈希密码。所以我只需要问,如果我把 ss 作为字符串,可以吗? OR var 会给出不同的结果。
  • 我相信它不会有什么不同,特别是如果你只用Response.Write写回它
  • 但如果我想将其作为密码保存在数据库中而不是 Responce.Write()
  • 因此,您必须完整描述您的问题才能获得完整的答案... :) - 写一个新问题并提供所有详细信息

标签: c# string cryptography var


【解决方案1】:

只需将ss 声明为System.String

根据Crypto.HashPassworddocumentation,返回值为System.String类型

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 2014-05-15
    • 2014-02-04
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多