为什么我们在变量名中使用_? [英] Why do we use _ in variable names?

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

问题描述

我见过像 _ image 这样的变量,想知道 _ 是什么意思?

I have seen variables like _ image and was wondering what _ meant?

推荐答案

它不意味着任何事情.将私有成员变量与方法和公共属性分开是一种常见的命名约定.例如:

It doesn't mean anything. It is rather a common naming convention for private member variables to keep them separated from methods and public properties. For example:

class Foo
{
   private int _counter;

   public int GetCounter()
   {
      return _counter;
   }

   public int SetCounter(int counter)
   {
      _counter = counter;
   }
}

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

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