我有一个名为的静态方法myStaticMethod
。定义如下:
public static void myStaticMethod(string strInputVal="Default")
{
if ("Is accessing Default Value") // how can i define this condition
{
//Do something
}
else
{
//Do some other task
}
}
现在,我可以按以下不同方式调用该方法:
myStaticMethod(); // will access default value
myStaticMethod("Some Value");// will use the passed value
myStaticMethod("Default"); // Here passing value and default value are same
在这里,我的问题是如何识别方法是访问默认值还是通过方法调用传递的值。
如果我定义条件像;
if (strInputVal == "Default")
{
// do operation here
}
这意味着所有函数调用均已满,
myStaticMethod("Default");
因为在这种情况下,该方法实际上访问传递的值,但是我的条件是它将访问默认值
+1到@Sinatr我只会加澄清。
public static void myStaticMethod(string strInputVal)
{
// Do what same part
}
// When you call this method it is
public static void myStaticMethod()
{
string strInputVal = "Default";
//Do something for default value
System.Console.WriteLine("I am indetified as called with default value");
myStaticMethod(strInputVal);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句