# [快速结贴]小问题一个,

kkun_3yue3 2008-07-10 04:57:57

string a = "0";
string b = "5.5";
string c = "";
string d = "50";
....略

(0+5.5+50)/3

...全文
149 9 打赏 收藏 转发到动态 举报

9 条回复

mytvgames 2008-07-10
• 打赏
• 举报

string[] strArray = { "5","5.5",""};
int numCount = 0;
int sum = 0;
foreach (string s in strArray) {
try {
double dtemp = double.Parse(s);
int intValue = (int)dtemp;
numCount++;
sum += intValue;
} catch {

}
}
double avg = sum / numCount;
syl2000 2008-07-10
• 打赏
• 举报

int myAvg(string[] pstr)
{
int iCnt = 0;
int iVal = 0;
foreach(string ss in pstr)
{
if(ss.Length > 0)
{
iCnt++;
iVal = iVal + Convert.ToInt32(ss);
}
}
int iRet = iVal/iCnt;
return iRet;
}
beancurd005 2008-07-10
• 打赏
• 举报

string a = "0";
string b = "5.5";
string c = "";
string d = "50";

List<string> list=new List<string>();

int count=0;
int total=0;
foreach(string s in list)
{
if(!String.IsNullOrEmpty(s))
{
total += Int32.Parse(s);
count ++;
}
}
if(count !=0)
{
double average = double(total/count);
}
halk 2008-07-10
• 打赏
• 举报

``````
int 除数 = 0;
double 被除数 = 0;
double 数;

if(double.TryParse(a, out 数)
{
除数 += 1;
被除数 += 数;
}
if(double.TryParse(b, out 数)
{
除数 += 1;
被除数 += 数;
}
if(double.TryParse(c, out 数)
{
除数 += 1;
被除数 += 数;
}

……

double 商 = 被除数 / (double)除数;
int 整数的商 = (int)商;
``````

jeason_jun 2008-07-10
• 打赏
• 举报

int n=0;
int sum=0;
double avg;
for(int i= 0;i<a.lenth;i++)
{
try
{
sum+=convert.toint32(a[i]);
n++;
}
catch{}
}

avg=sum/n;
Macosx 2008-07-10
• 打赏
• 举报

string[] rawValues = { "0", "5.5", "", "50" };
double val=0;
var ave = from numString in rawValues
where Double.TryParse(numString, out val)
select val;

Console.WriteLine(ave.Average());

• 打赏
• 举报

nattystyle 2008-07-10
• 打赏
• 举报

nattystyle 2008-07-10
• 打赏
• 举报

(0+5.5+50)/3

string b = "5.5";

110,024

• 近7日
• 近30日
• 至今