Member 'object.Equals(object, object)' cannot be accessed with an instance reference; qualify it with a type name instead

后端 未结 7 524
粉色の甜心
粉色の甜心 2021-01-17 10:59

When I used the following code in C#...

int totalValue = 0;
int total = 0;
totalValue = int.Parse(Session[\"price\"].ToString()) * int.Parse(Session[\"day\"]         


        
7条回答
  •  温柔的废话
    2021-01-17 11:42

    Your code is not strong.

    Session is an object, it can be null, so if you want to use its value, please check the session first, and even the session's value is not a integer value.

    I suggest you to do like this:

    int? i = Session["s"] == null ? null : Parser.ParseInt(Session["s"].ToString());
    

提交回复
热议问题