希望我问得正确。
我有这堂课:
class ListUtilities
{
private List<string> _datalist;
public ListUtilities(List<string> datalist)
{
_datalist = datalist;
}
//Method to calculate age from a date
private int getAge(string bdaystr)
{
DateTime today = DateTime.Today;
DateTime bday = new DateTime(Convert.ToInt32(bdaystr.Substring(0, 4)), Convert.ToInt32(bdaystr.Substring(4, 2)), Convert.ToInt32(bdaystr.Substring(6, 2)));
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age)) age--;
return age;
}
//Method to print the data List
public void printDataList()
{
for (int i = 0; i < _datalist.Count; i++)
{
Console.WriteLine(_datalist.ElementAt(i));
}
}
//Method to calculate and print the ages
public void printAges()
{
List<int> ages = new List<int>();
for (int i = 0; i < _datalist.Count; i++)
{
string s = _datalist.ElementAt(i);
string[] data = s.Split(',');
ages.Add(getAge(data[3]));
}
Console.WriteLine("Ages:");
for (int i = 0; i < ages.Count; i++)
{
Console.WriteLine(ages.ElementAt(i));
}
}
//Method to search by surname
public string searchBySurname(string surname)
{
string res = "";
res = _datalist.Find(delegate(String str)
{
string[] data = str.Split(',');
string sname = data[1];
if (sname == surname)
return true;
else
return false;
});
return res;
}
//Method to search by phone number
public string searchByPhoneNumber(string phone)
{
string res = "";
res = _datalist.Find(delegate(String str)
{
string[] data = str.Split(',');
string phn = data[4];
if (phn == phone)
return true;
else
return false;
});
return res;
}
//Method to search by age
public string searchByAge(int age)
{
string res = "";
res = _datalist.Find(delegate(String str)
{
string[] data = str.Split(',');
int age2 = Convert.ToInt32(getAge(data[3]));
if (age2 == age)
return true;
else
return false;
});
return res;
}
//Method to sort by surname
public int sortBySurname(string x, string y)
{
string[] data_x = x.Split(',');
string sname_x = data_x[1];
string[] data_y = y.Split(',');
string sname_y = data_y[1];
return String.Compare(sname_x, sname_y);
}
//Method to sort by phone number
public int sortByPhoneNumber(string x, string y)
{
string[] data_x = x.Split(',');
int phn_x = Convert.ToInt32(data_x[4]);
string[] data_y = y.Split(',');
int phn_y = Convert.ToInt32(data_y[4]);
return phn_x.CompareTo(phn_y);
}
//Method to sort by age
public int sortByAge(string x, string y)
{
string[] data_x = x.Split(',');
int age_x = Convert.ToInt32(data_x[3]);
string[] data_y = y.Split(',');
int age_y = Convert.ToInt32(data_y[3]);
return age_y.CompareTo(age_x);
}
}
我想把它编译成一个 .DLL 文件。我试过用这样的控制台来做:
csc /target:library /out:MathLibrary.DLL Add.cs Mult.cs
并将该类放在类库项目中并构建它,我在这两种情况下都得到了 DLL 文件,但是当我想使用该 DLL 时问题就来了。
我创建了一个新项目,并且确实引用了 DLL 文件,但是当我想使用它时,这就是问题所在:
而且,似乎 DLL 中没有任何内容:
此致