本文介绍了如何在C#中使用class属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很擅长.NET并学习这些东西。我有一个来自相机库的类,它在我们调用下面的GetValue()方法时给出属性值。

I'm pretty new to .NET and learning the things. I have a class from a camera library which gives the property value when we call GetValue() method as below.

camera.Parameters[PLCamera.Width].GetValue();

我不确定这是如何工作的。两个方括号中给出的 PLCamera.Width 是枚举吗?本声明中基本上发生了什么?当我看到 PLCamera 类时,它有许多这样的属性。我想创建一个公共函数,它给出了作为参数给出的任何属性。



我尝试了什么:



我试过代码 camera.Parameters [PLCamera.Width] .GetValue(); 并获得 PLCamera.Width 。我想知道这基本上是如何工作的?



CHM图书馆文档可以在 []

I'm unsure how does that work. Is that PLCamera.Width given in two square braces is an enum? What essentially happening in this statement? When I saw PLCamera class, it has numerous such properties. I want to create a public function which gives any property given as argument.

What I have tried:

I have tried the code camera.Parameters[PLCamera.Width].GetValue(); and it gets the PLCamera.Width. I want to know how this essentially works?

CHM library doc can be found at Pylon - Google Drive[^]

推荐答案

public static class PLCamera
    {
    public static const string Width = "Width";
    ...
    }
public class ParameterBlock
    {
    public int GetValue() { return 0; }
    ...
    }
private Dictionary<string, ParameterBlock> Parameters = new Dictionary<string, ParameterBlock>();
...
    int x = Parameters[PLCamera.Width].GetValue();



如果它是枚举,则可以这样做:


If it's an enum, then it could be done like this:

private  Dictionary<PLCamera, ParameterBlock> Parameters = new Dictionary<PLCamera, ParameterBlock>();
...
    int x = Parameters[PLCamera.Width].GetValue();


这篇关于如何在C#中使用class属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 16:54