我想使用IDisposable接口清除内存中没有使用的任何资源.
public class dispose:IDisposable
{
public void Dispose()
{
throw new NotImplementedException();
}
public void fun()
{
PizzaFactory _pz = new PizzaFactory(); //
}
}
Run Code Online (Sandbox Code Playgroud)
我想处理pz对象,当没有ref它存在时.请让我知道怎么做.
我正在写一个Linq查询只是为了学习.
var result = Process.GetProcesses()
.Where(p => p.WorkingSet64 > 20 * 1024 * 1024)
.OrderByDescending(p => p.WorkingSet64)
.Select(p => new {p.Id,p.ProcessName,p.WorkingSet64 });
Run Code Online (Sandbox Code Playgroud)
我想迭代到结果
foreach(process in result) //error-type or namespace process could not be found.
{
Console.WriteLine(Process.ProcessName);
}
Run Code Online (Sandbox Code Playgroud)
我想迭代结果并在控制台上打印每个进程名称.
我做错了什么.
如果对象不满足某些条件,我想从集合中删除一个对象
foreach (var data in infData)
{
if(data.Id==0)
{
//Remove this object from the collection
}
}
Run Code Online (Sandbox Code Playgroud)
这该怎么做.
编辑:这是完整的代码
foreach (var data in infData)
{
//Validate Offence Code
IQueryable<Ref_OffenceCode> allRows = dbContext.Ref_OffenceCode;
if (allRows.Where(p => p.Code == data.offenceCode && p.StartDate<=data.offenceDate ).Count() == 0)
{
invalidCount += 1;
}
//Validate Location Code
//IQueryable<Ref_OffenceCode> allRows = dbContext.Ref_OffenceCode;
if (invalidCount != 0)
{
infData.Remove(data);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个功能
protected void bindCurrencies(DropDownList drp)
{
drp.DataSource = dtCurrencies;
drp.DataTextField = "CurrencyName";
drp.DataValueField = "CurrencyID";
drp.DataBind();
drp.Items.Insert(0, new ListItem("Please Select"));
}
Run Code Online (Sandbox Code Playgroud)
我正在使用此绑定下拉列表.但有时我还需要绑定一个ListBox.我不想为listbox编写不同的函数.我该怎么做 我认为在这里使用泛型方法.但我对泛型不了解.