我无法从IEnumerable列表中删除元素,但此列表是对List的引用,List是其他类的私有属性.如果我放入personsCollection.Remove(theElement)同一个类(类管理器),它的工作完美,但我需要删除该元素,因为其他类(类ManagerDelete).请问我该怎么做?谢谢.
class Other
{
//Some code
public IEnumerable<Person> SearchByPhone (string value)
{
return from person in personCollection
where person.SPhone == value
select person;
}
}
class ManagerDelete
{
//Some code
IEnumerable<Person> auxList= SearchByPhone (value);
//I have a method for delete here
}
class Manager
{
//Some code
private List<Person> personsCollection = new List<Person>();
}
Run Code Online (Sandbox Code Playgroud) 我有一个这样的课:
class Person
{
private String sName;
private String sPhone;
private String sAge;
private String sE_Mail;
// … code …
}
Run Code Online (Sandbox Code Playgroud)
而且我必须通过从用户收到的值进行搜索,它可以是这个类的任何属性.我也有这个:
public IEnumerable<Person> SearchByPhone(string value)
{
return from person in personCollection
where person.**SPhone** == value
select person;
}
Run Code Online (Sandbox Code Playgroud)
我有四种这样的方法,唯一的区别是属性.请问,任何人都可以告诉我如何只用一种方法做到这一点或者不可能做到这一点?谢谢.
对于类型Loan,Client和Book,我有三种类似的方法.我是编程学生,我想知道是否可以传入参数,一个与这3个类匹配的泛型类型,我的意思是在括号之间传递一个不同的类型,比如<T>三个类只有一个方法.我试过<object>但它不起作用.
public void LoadStoreLoans(ObservableCollection<Loan> loansCollection)
{
IList<Loan> loans = db.Query<Loan>(); //db4o
loansCollection = loans != null ? new ObservableCollection<Loan>(loans) : new ObservableCollection<Loan>();
}
Run Code Online (Sandbox Code Playgroud)
Thnks.
我可以在没有正则表达式的情况下限制控制台应用中的电话号码 我有这个代码,但它不适用于国际号码,从00开始.
static public bool CheckPhoneNumb (string phoneNumber)
{
long lphoneNumber;
return ((phoneNumber.Length >= 9) && phoneNumber.Length <= 15) &&
(long.TryParse (phoneNumber, out lphoneNumber))) ? true : false;
}
Run Code Online (Sandbox Code Playgroud)
Thnks.