没有逻辑的方法中的静态数据应该返回结果 [英] Static data in the method with no logic should return the result
本文介绍了没有逻辑的方法中的静态数据应该返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public string ABD(int value)
{
1 =Capgemini
2 =IBM
3 =埃森哲
}
它应该通过将int参数传递给方法来返回字符串结果。
没有逻辑在方法中返回。
如何在没有任何逻辑的情况下得到结果。
我尝试过:
我试过检查任何预定义的函数,如contains。
解决方案
你的意思是
public string ABD( int value )
{
string result = string .Empty;
switch ( value )
{
case 1 :
result = 凯捷跨度>;
break ;
case 2 :
result = IBM;
break ;
case 3 :
result = 埃森哲;
break ;
默认:
// 在这里处理错误的输入值
break ;
}
返回结果;
}
?
还有其他几种方法可以实现这种方法。
您可能应该使用数组(string []),List< string>或字典< int,string>。所有这些只允许你通过将值
传递到它来获取字符串。
阵列教程(C#) [ ^ ]
List(T)Class(System.Collections.Generic ) [ ^ ]
字典(TKey,TValue)类(System.Collections.Generic) [ ^ ]
我没有了解你的结果,没有任何l ogic
对于这种情况,你可以尝试切换
public string ABD(int value)< br $>
{
开关(价值)
{
case1:
console.writeln(Capgemini);
休息;
案例2:
控制台。 writeln(IBM);
休息;
案例3:
console.writeln(埃森哲);
休息;
}
}
谢谢
Priyadarshini
public string ABD(int value)
{
1="Capgemini"
2="IBM"
3="Accenture"
}
It should return the string result by passing the int parameter to the method.
No logic is return in the method .
How should I get the result with out any logic.
What I have tried:
I tried by checking with any predefined functions like contains.
解决方案
Do you mean
public string ABD(int value) { string result = string.Empty; switch (value) { case 1: result = "Capgemini"; break; case 2: result = "IBM"; break; case 3: result = "Accenture"; break; default: // handle wrong input value here break; } return result; }
?
There are several other ways to implement such method.
You're probably supposed to use either an array ( string[] ), a List<string> or a Dictionary<int, string>. All of those would allow you to "get a string out" just by passing thevalue
"into" it.
Arrays Tutorial (C#)[^]
List(T) Class (System.Collections.Generic)[^]
Dictionary(TKey, TValue) Class (System.Collections.Generic)[^]
Hi ,
I didnt understand your concept of getting result without any logic
For this case may be you can try switch
public string ABD(int value)
{
Switch(value)
{
case "1":
console.writeln("Capgemini");
break;
case "2":
console.writeln("IBM");
break;
case "3":
console.writeln("Accenture");
break;
}
}
Thanks
Priyadarshini
这篇关于没有逻辑的方法中的静态数据应该返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文