是否可以具有接受任意数量的任何类型的变量的Function? [英] Is it possible to have a Function that takes any number of variables of any type?

查看:55
本文介绍了是否可以具有接受任意数量的任何类型的变量的Function?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的函数,该函数需要一个字符串,并使用该字符串向我发送电子邮件(该函数在调试实时网站时使用)

I have a simple function that takes a string and sends an email to me with that string (the function is used when debugging a live site)

public void errEmailV1(string strVars)
{
    sendEmail("me@email","emailSubject",strVars);  
}

自然可以校准函数并发送多个变量:

Naturally to cal the function and send over multiple variables I'd:

Functions funcs = new Functions();
funcs.errEmailV1(someVariableThatisAString+", "+someIntVariable.ToString() +"...");

后来我改进了功能,使其能够更快地调用它

I later evolved my function to be able to call it faster

Functions funcs = new Functions();
funcs.errEmailV2(someVariableThatisAString,someIntVariable.ToString());

public void errEmailV2(params String[] paths)
{
    string strVars="";
    //a rather simplified version of the loop:
    for (int i = 0; i < paths.Length; i++)
    {
        strVars+= paths[i];
    }
    sendEmail("me@email","emailSubject",strVars);  
}

我怀疑是这样,但是我的V3是否有可能采用任意数量的字符串,整数和布尔值(我很少发送其他类型的字符串),而不必总是添加 ToString()?

I doubt it is, but is it possible for my V3 to take any number of strings, ints and booleans (I rarely if ever send any other types) instead of having to always add ToString() ?

推荐答案

使用 params对象[]

这篇关于是否可以具有接受任意数量的任何类型的变量的Function?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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