Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
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.
Posted
Comments
_Asif_ 8-Feb-16 3:26am    
"How should I get the result with out any logic" Can't understand what you meant here!
BillWoodruff 8-Feb-16 13:40pm    
There is no such thing as "without any logic."

If we do your homework, and you avoid interaction with your instructor and other people in your class: you will learn nothing.

Do you mean
C#
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.
 
Share this answer
 
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 the value "into" it.

Arrays Tutorial (C#)[^]
List(T) Class (System.Collections.Generic)[^]
Dictionary(TKey, TValue) Class (System.Collections.Generic)[^]
 
Share this answer
 
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
 
Share this answer
 
Comments
Usha Sanjee 8-Feb-16 3:58am    
I have answered that we can use conditional statments.But they need the result without any conditions.Is there predefined functions which checks the condition and return the result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900