can i use a keyword as a propertyname in vb .net?

杀马特。学长 韩版系。学妹 提交于 2021-02-09 17:55:01

问题


I have to serialize/deserialize a class into a JSON string/and return. The JSON Strinig must contain the "error" string (like: {error:"something strange occoured", id:23, result:"xxxxx"}), which specifies the occoured error.

How can i implement a class like:

Public Class JsonResponse
    Public result As JsonResult
    Public error As String
    Public id As Integer
 End Class

If i do this, the word 'error' is invalid.

Thanks


回答1:


Surround it with square brackets

Public Class JsonResponse
    Public result As JsonResult
    Public [error] As String
    Public id As Integer
 End Class

HTH




回答2:


Use [] around the name:

Public Class JsonResponse
   Public result As JsonResult
   Public [error] As String
   Public id As Integer
End Class


来源:https://stackoverflow.com/questions/5868777/can-i-use-a-keyword-as-a-propertyname-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!