C#中的属性get和set到底是啥意思

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#中的属性get和set到底是啥意思相关的知识,希望对你有一定的参考价值。

private int a;
private int b
getxxx setxxx
变量a还正常,b明显不合常理么,有什么作用,应该怎么使用?
还有,在set中总是有一个value,但是在哪里都没有定义它,这个value又是干什么的呢

get是给属性赋值,set是取属性的值。

get、set用法:

一是隐藏组件或类内部的真是成员;

二是用来建立约束的,比如,实现“有我没你”这种约束;

三是用来响应属性变化事件,当属性变化是做某事,只要写在set方法里就行。

当你想读出或写入属性的值时,存取标志限定了被实现的语句。用于读出属性的值的存取标志记为关键字get,而要修改属性的值的读写符标志记为set。

下面是示例代码:

public class Student 
 
private string name 
public string Name 
 
setname=value;//这里是给私有属性name赋值 
getreturn name;//这里取出私有属性name的值 
 
参考技术A get和set是C#定义属性的规范,看以下示例:
public class Person

private string _name;
public string Name

get return _name; //可以通过 Person的实例来访问Name,返回私有变量_name的值
private set _name = value; //不允许外部赋值,只能在Person内部赋值,value就是赋过来的值

追问

在你上面的例子上加一句,比如说:_name="12345";那是不是value就是12345了?

追答

这个Name属性指向了私有变量_name,_name的值就是Name的值,但12345跟private set _name = value; 中的value不是一回事,这个value只来自赋值,比如 person.Name="abcd" 那value就是指"abcd"了

本回答被提问者和网友采纳
参考技术B private int a;是类变量

private int b
getxxx setxxx

是类属性

value表示这个属性本身
参考技术C 这是C#的一个语法规则! 参考技术D 不知道你学过java没有,不就是对象封装吗?

interpreter.get_input_details() 中的“量化”是啥意思?

【中文标题】interpreter.get_input_details() 中的“量化”是啥意思?【英文标题】:What does 'quantization' mean in interpreter.get_input_details()?interpreter.get_input_details() 中的“量化”是什么意思? 【发布时间】:2019-07-16 17:27:30 【问题描述】:

使用 tflite 并获取解释器的属性,例如:

print(interpreter.get_input_details())

['name': 'input_1_1', 'index': 47, 'shape': array([  1, 128, 128,   3], dtype=int32), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.003921568859368563, 0)]

'quantization': (0.003921568859368563, 0) 是什么意思?

【问题讨论】:

【参考方案1】:

表示量化参数值:输入张量的scale和zero_point。

这是使用公式将量化的 uint8 数 q 转换为浮点数 f 所必需的:

f = (q - zero_point) * scale

【讨论】:

【参考方案2】:

很遗憾,documentation of get_input_details 没有解释:

Returns: A list of input details.

但是如果你查看源代码get_input_details,它会调用_get_tensor_details (source),并且这个函数确实记录了它:

    """Gets tensor details.
    Args:
      tensor_index: Tensor index of tensor to query.
    Returns:
      A dictionary containing the following fields of the tensor:
        'name': The tensor name.
        'index': The tensor index in the interpreter.
        'shape': The shape of the tensor.
        'quantization': Deprecated, use 'quantization_parameters'. This field
            only works for per-tensor quantization, whereas
            'quantization_parameters' works in all cases.
        'quantization_parameters': The parameters used to quantize the tensor:
          'scales': List of scales (one if per-tensor quantization)
          'zero_points': List of zero_points (one if per-tensor quantization)
          'quantized_dimension': Specifies the dimension of per-axis
              quantization, in the case of multiple scales/zero_points.

什么意思?

这些量化参数是用于量化的值(将一系列数字从一个范围转换为另一个更有限的范围,例如 0-10 到 0-1)。在 TensorFlow 中,这专门用于表示当数据类型更改为支持较少数字的数据类型时:例如float32 到 float16,或 float32 到 uint8,或 float16 到 int8。反量化则相反(例如,当您想从量化为 uint8 且量化输出在 0-255 之间的模型中获取概率时)。

数学很简单,就像更一般的形式规范化(使范围从 (0 到 1)):

量化:q = (f / s) + z 去量化:f = (q - z) * s 有关此量化方程的更多信息,请参阅Quantization Specification。

注意: Aleksandr Kondratyev 的方程 f = (q - zero_point) * scale 实际上是反量化,因为它需要 q(量化值)并为您提供 f(浮点数)。当然,您可以将等式倒转得到另一个。

【讨论】:

以上是关于C#中的属性get和set到底是啥意思的主要内容,如果未能解决你的问题,请参考以下文章

C# 中的“SKU”(属性)是啥意思?

JAVA中Bean是啥?

C#面向对象基础2

c#属性的get和set的用法

C#中用于组件的背景图像布局的5个选项分别是啥意思?

JAVA反射Field