简体   繁体   English

创建具有多个属性的自己的类

[英]Create own class with more than one property

i have the following class: 我有以下课程:

namespace Mentionfunctions
{
    class MFunctions
    {
        public bool availability(string ean)
        {
             //do
             return true;
        }
    }      
}

I call this one with 我称这个为

MFunctions mf = new MFunctions();
mf.availability(EAN);

I want to add a property to call the function with a different "mode" 我想添加一个属性以使用不同的“模式”调用函数

I want to do something like: 我想做类似的事情:

mf.availability.global(EAN);
mf.availability.onlysupplier(EAN);

I googled this for ours but i'm not sure how do to that or i'm using the wrong words for searching. 我用谷歌搜索了一下,但是我不确定该怎么做,或者我使用了错误的单词进行搜索。

You can use enums for that: 您可以为此使用枚举:

enum Mode
{
   global,
   onlysupplier
}

public bool availability(string ean, Mode m) { }

Then you can call your method like this: 然后,您可以像下面这样调用您的方法:

mf.availability(EAN, Mode.global);

Don't use a property to change the behaviour of a function. 不要使用属性来更改函数的行为。 Use an additional argument to the function instead: 使用该函数的附加参数:

bool availability(string ean, string mode);

Then make mode an Enumeration 然后将模式设为枚举

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM