在变量名的开头使用数字 [英] Using numbers at the beginning of variable name

查看:91
本文介绍了在变量名的开头使用数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从SQL数据库映射到c#中的对象.问题是,其中一列不幸地被命名为"100_hrs".因此,当我制作C#对象时,在声明中出现错误:

I'm mapping up data from an SQL database into an object in c#. The problem is, one of the columns is unfortunately named "100_hrs". So when I am making my C# object, I get an error in the declaration:

public float 100_hrs {get; set;}

我尝试在前面使用 @ ,但是它不起作用.如果该属性的名称与表列的名称不同,则不会映射该属性.我该如何映射呢?

I've tried using @ in front but it does not work. If the property is not named the same as the table column, then it does not map up. How can I map this up?

推荐答案

回答 @ 不起作用的原因.

@ 允许您使用关键字名称声明变量,不允许使用无效的标记.

@ lets you declare variables with keywords names, it doesn't allow you to use invalid tokens.

MSDN

关于主要问题,似乎您应该更改表列名称.
如果您使用某种映射引擎,例如EntityFramework的NHibernate,则可以更改映射文件.示例:

Regarding to the main question, it seems like you should change the table column name.
If you're using some sort of mapping engine like NHibernate of EntityFramework, you can change the mapping file. Example:

[Column("100_hrs")]
public float hrs100 {get; set;}

这篇关于在变量名的开头使用数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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