double retCondition = 0.0;
str = "Sub1 = A+B-C+D-A,Sub2=D+E,Sub3=F+G";
string[] words1 = str.Split('#');
Dictionary<string, double> TempSub = new Dictionary<string, double>();
for (int i = 0; i < words1.Length; i++)
{
double n = 0.0;
string[] words2 = words1[i].Split('='); // Again splitting the values for Sub1 = A+B // Second split
string[] words3 = words2[1].Split('+');
for (int j = 0; j < words3.Length; j++)
{
double m = 0.0;
double sub = 0.0;
string[] words4 = words3[j].Split('-');
for (int k = 0; k < words4.Length; k++)
{
switch (words4[k].Trim())
{
case "A":
sub = 10;
break;
case "B":
sub = 20;
break;
case "C":
sub = 30;
break;
case "D":
sub = 180;
break;
default:
sub = 0;
break;
}
if (k == 0)
{
m += sub;
}
else
{
m -= sub;
}
}
n += m;
}
TempSub.Add(words2[0], n); // So Sub1 will be the variables
}
then change the strReturnValue and retCondition variable declarations to a dictionary as well:
var strReturnvalue = GetMarks(A,B,C,D,E,F,str); // Main and returns Tempsub value
and
Dictionary<string, double> retCondition;
The whole thing:
var strReturnvalue = GetMarks(A, B, C, D, E, F, str); // Main and returns Tempsub value
public static Dictionary < string, double > GetMarks(double A, double B, double C, double D, double E, double F, String str) {
Dictionary < string, double > retCondition;
str = "Sub1 = A+B-C+D-A,Sub2=D+E,Sub3=F+G";
string[] words1 = str.Split('#');
Dictionary < string, double > TempSub = new Dictionary < string, double > ();
for (int i = 0; i < words1.Length; i++) {
double n = 0.0;
string[] words2 = words1[i].Split('='); // Again splitting the values for Sub1 = A+B // Second split
string[] words3 = words2[1].Split('+');
for (int j = 0; j < words3.Length; j++) {
double m = 0.0;
double sub = 0.0;
string[] words4 = words3[j].Split('-');
for (int k = 0; k < words4.Length; k++) {
switch (words4[k].Trim()) {
case "A":
sub = 10;
break;
case "B":
sub = 20;
break;
case "C":
sub = 30;
break;
case "D":
sub = 180;
break;
default:
sub = 0;
break;
}
if (k == 0) {
m += sub;
} else {
m -= sub;
}
}
n += m;
}
TempSub.Add(words2[0], n); // So Sub1 will be the variables
}
retCondition = TempSub // Error
return retCondition;
}
-----------------
Please remember to click "Mark as Answer" the responsES that resolved your issue.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
209 Points
701 Posts
Dictionary - How to return Dictionary value as a method or function.
Jul 18, 2017 12:22 PM|gani7787|LINK
Hi,
How to return TempSub value as method or function.
See my full code.
double strReturnvalue = GetMarks(A,B,C,D,E,F,str); // Main and returns Tempsub value
public static double GetMarks(double A,double B,double C,double D,double E,double F,String str)
double retCondition = 0.0;
str = "Sub1 = A+B-C+D-A,Sub2=D+E,Sub3=F+G";
string[] words1 = str.Split('#');
Dictionary<string, double> TempSub = new Dictionary<string, double>();
for (int i = 0; i < words1.Length; i++)
{
double n = 0.0;
string[] words2 = words1[i].Split('='); // Again splitting the values for Sub1 = A+B // Second split
string[] words3 = words2[1].Split('+');
for (int j = 0; j < words3.Length; j++)
{
double m = 0.0;
double sub = 0.0;
string[] words4 = words3[j].Split('-');
for (int k = 0; k < words4.Length; k++)
{
switch (words4[k].Trim())
{
case "A":
sub = 10;
break;
case "B":
sub = 20;
break;
case "C":
sub = 30;
break;
case "D":
sub = 180;
break;
default:
sub = 0;
break;
}
if (k == 0)
{
m += sub;
}
else
{
m -= sub;
}
}
n += m;
}
TempSub.Add(words2[0], n); // So Sub1 will be the variables
}
retCondition = TempSub ??????? // Error
return retCondition;
}
How to return TempSub value to method or function..?
Participant
1380 Points
608 Posts
Re: Dictionary - How to return Dictionary value as a method or function.
Jul 18, 2017 01:31 PM|JBetancourt|LINK
change the return type of your method to Dictionary<string,double>:
then change the strReturnValue and retCondition variable declarations to a dictionary as well:
and
The whole thing:
Please remember to click "Mark as Answer" the responsES that resolved your issue.
Contributor
2260 Points
815 Posts
Re: Dictionary - How to return Dictionary value as a method or function.
Jul 19, 2017 05:32 AM|Billy Liu|LINK
Hi gani7787,
You could refer to my answer in your previous post:
https://forums.asp.net/p/2125211/6153447.aspx
Best Regards,
Billy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.