本文整理汇总了C#中Common.List.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# List.FirstOrDefault方法的具体用法?C# List.FirstOrDefault怎么用?C# List.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Common.List
的用法示例。
在下文中一共展示了List.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateKnownProperties
public static void CreateKnownProperties(List<Driver> drivers)
{
try
{
RMHelper.Create(drivers);
MROHelper.Create(drivers);
AMP4Helper.Create(drivers);
MDUHelper.Create(drivers);
BUZHelper.Create(drivers);
foreach (var driverType in new List<DriverType>() { DriverType.Pump, DriverType.JokeyPump, DriverType.Compressor, DriverType.DrenazhPump, DriverType.CompensationPump })
{
var driver = drivers.FirstOrDefault(x => x.DriverType == driverType);
BUNHelper.Create(driver);
}
MPTHelper.Create(drivers);
DetectorsHelper.Create(drivers);
AM_1_Helper.Create(drivers);
AM1_T_Helper.Create(drivers);
AM1_O_Helper.Create(drivers);
ControlCabinetHelper.Create(drivers);
FanCabinetHelper.Create(drivers);
MRO2Helper.Create(drivers);
}
catch (Exception e)
{
Logger.Error(e, "DriverConfigurationParametersHelper.CreateKnownProperties");
}
}
示例2: MergeItems
private List<CalendarItem> MergeItems(List<CalendarItem> newItems, List<CalendarItem> fromRepo)
{
var result = new List<CalendarItem>();
var newModels = newItems.Except(fromRepo, new CalendarItemEqualityComparer()).ToList();
var updatet = fromRepo.Except(newModels,new CalendarItemEqualityComparer()).ToList();
updatet.ForEach(x =>
{
var model = newItems.FirstOrDefault(y => y.Id == x.Id);
if (model != null)
{
model.SyncStatus.CalenadCalendarItemStatus = IsModified(model, x)
? CalendarItemStatus.Updated
: CalendarItemStatus.Unmodified;
result.Add(model);
}
});
var deleted = fromRepo.Where(x => x.Start.Date >= DateTime.Now.Date).Except(newItems).Except(updatet);
newModels.ForEach(x => x.SyncStatus.CalenadCalendarItemStatus = CalendarItemStatus.New);
deleted.ForEach(x =>
{
x.SyncStatus.CalenadCalendarItemStatus = CalendarItemStatus.Deleted;
result.Add(x);
});
result.AddRange(newModels);
return result.OrderBy(x => x.Start).ToList();
}
示例3: Main
static void Main(string[] args)
{
int totalCount = 3;
List<Student> listStudent = new List<Student>();
for (int i = 0; i < 3; i++)
{
Student objStudent = new Student();
Console.Write("Please enter the Student ID: ");
objStudent.StudentId = Int32.Parse(Console.ReadLine());
Console.Write("Please enter the Student Name: ");
objStudent.Name = Console.ReadLine();
listStudent.Add(objStudent);
}
//Query to get by name - only first occurence
//Student student = listStudent.First(x => x.Name == "Karthik");
Student student = listStudent.FirstOrDefault(x => x.Name == "Karthik");
if(student != null)
Console.WriteLine(string.Format("ID: {0} Name: {1}", student.StudentId, student.Name));
//Query to get by name - all occurences
//IEnumerable<Student> stdList = listStudent.Where(x => x.Name == "Karthik");
IEnumerable<Student> stdList = listStudent.Where(x => x.StudentId >= 20);
foreach (var student1 in stdList)
{
Console.WriteLine(string.Format("ID: {0} Name: {1}", student1.StudentId, student1.Name));
}
listStudent.Sort((std1, std2) => std1.Name.CompareTo(std2.Name));
listStudent.ForEach(x=>Console.WriteLine(x.Name));
}
示例4: LoadData
public async void LoadData()
{
try
{
_allNamedays = await NamedayRepository.GetAllNamedaysAsync();
PerformFiltering();
LoadingState = LoadingStates.Loaded;
}
catch
{
LoadingState = LoadingStates.Error;
}
var now = DateTime.Now;
SelectedNameday = _allNamedays.FirstOrDefault(
d => d.Day == now.Day && d.Month == now.Month);
}
示例5: ResetAllStates
public static void ResetAllStates()
{
try
{
var resetItems = new List<ResetItem>();
foreach (var device in Devices)
{
foreach (var deviceDriverState in device.DeviceState.ThreadSafeStates)
{
if (deviceDriverState.DriverState.IsManualReset)
{
var resetItem = new ResetItem()
{
DeviceState = device.DeviceState
};
resetItem.States.Add(deviceDriverState);
var existringResetItem = resetItems.FirstOrDefault(x => x.DeviceState == resetItem.DeviceState);
if (existringResetItem != null)
{
foreach (var driverState in resetItem.States)
{
if (existringResetItem.States.Any(x => x.DriverState.Code == driverState.DriverState.Code) == false)
existringResetItem.States.Add(driverState);
}
}
else
{
resetItems.Add(resetItem);
}
}
}
}
FiresecManager.ResetStates(resetItems);
}
catch (Exception e)
{
Logger.Error(e, "FiresecManager.ResetAllStates");
}
}
示例6: DeviceControlViewModel
public DeviceControlViewModel(Device device)
{
Device = device;
ConfirmCommand = new RelayCommand(OnConfirm, CanConfirm);
Blocks = new List<BlockViewModel>();
foreach (var property in device.Driver.Properties)
{
if (property.IsControl)
{
var blockViewModel = Blocks.FirstOrDefault(x => x.Name == property.BlockName);
if (blockViewModel == null)
{
blockViewModel = new BlockViewModel()
{
Name = property.BlockName
};
Blocks.Add(blockViewModel);
}
blockViewModel.Commands.Add(property);
}
}
}
示例7: OnResetAll
void OnResetAll()
{
var resetItems = new List<ResetItem>();
foreach (var alarm in allAlarms)
{
var resetItem = alarm.GetResetItem();
if (resetItem != null)
{
var existringResetItem = resetItems.FirstOrDefault(x => x.DeviceState == resetItem.DeviceState);
if (existringResetItem != null)
{
foreach (var driverState in resetItem.States)
{
if (existringResetItem.States.Any(x => x.DriverState.Code == driverState.DriverState.Code) == false)
existringResetItem.States.Add(driverState);
}
}
else
{
resetItems.Add(resetItem);
}
}
}
FiresecManager.ResetStates(resetItems);
AllAlarmsResetingTimer = new DispatcherTimer();
AllAlarmsResetingTimer.Interval = TimeSpan.FromSeconds(2);
AllAlarmsResetingTimer.Tick += new EventHandler(AllAlarmsResetingTimer_Tick);
AllAlarmsResetingTimer.Start();
IsAllAlarmsReseting = true;
}
示例8: Translate
ExportPassJournalItem Translate(PassJournal tableItem, List<Employee> employees)
{
var employee = employees.FirstOrDefault(x => x.UID == tableItem.EmployeeUID);
var zone = GKManager.SKDZones.FirstOrDefault(x => x.UID == tableItem.ZoneUID);
return new ExportPassJournalItem
{
UID = tableItem.UID,
EmployeeUID = tableItem.EmployeeUID != null ? tableItem.EmployeeUID.Value : Guid.Empty,
EmployeeFIO = employee != null ? employee.LastName + " " + employee.FirstName + " " + employee.SecondName : "",
EnterDateTime = tableItem.EnterTime,
ExitDateTime = tableItem.ExitTime != null ? tableItem.ExitTime.Value : new DateTime(),
ZoneUID = tableItem.ZoneUID,
ZoneNo = zone != null ? zone.No : -1
};
}
示例9: FindDevicesOnShleif
bool FindDevicesOnShleif(GKDevice kauDevice, int shleifNo, GKProgressCallback progressCallback, Guid clientUID)
{
var shleifDevice = kauDevice.Children.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_KAU_Shleif && x.IntAddress == shleifNo + 1);
progressCallback.Title = "Автопоиск на АЛС " + (shleifNo + 1) + " устройства " + kauDevice.PresentationName;
progressCallback.CurrentStep = 0;
progressCallback.StepCount = 256;
using (var gkLifecycleManager = new GKLifecycleManager(kauDevice, "Автопоиск на АЛС " + (shleifNo + 1)))
{
var deviceGroups = new List<DeviceGroup>();
var devices = new List<GKDevice>();
for (int address = 1; address <= 255; address++)
{
gkLifecycleManager.Progress(address, 255);
GKProcessorManager.DoProgress("Поиск устройства с адресом " + address, progressCallback, clientUID);
if (progressCallback.IsCanceled)
{
Error = "Операция отменена";
return false;
}
var bytes = new List<byte>();
bytes.Add(0);
bytes.Add((byte)address);
bytes.Add((byte)shleifNo);
var result2 = new SendResult("");
for (int i = 0; i < 3; i++)
{
if (progressCallback.IsCanceled)
{
Error = "Операция отменена";
return false;
}
result2 = SendManager.Send(kauDevice, 3, 0x86, 6, bytes, true, false, 3000);
if (!result2.HasError)
break;
}
if (!result2.HasError)
{
if (result2.Bytes.Count == 6)
{
var driverTypeNo = result2.Bytes[1];
var serialNo = BytesHelper.SubstructInt(result2.Bytes, 2);
var driver = GKManager.Drivers.FirstOrDefault(x => x.DriverTypeNo == (ushort)driverTypeNo);
if (driver != null)
{
var device = new GKDevice();
device.Driver = driver;
device.DriverUID = driver.UID;
device.IntAddress = (byte)address;
devices.Add(device);
var deviceGroup = deviceGroups.FirstOrDefault(x => x.SerialNo == serialNo);
if (deviceGroup == null || (serialNo == 0 || serialNo == -1) || (driver.DriverType != GKDriverType.RSR2_AM_1 && driver.DriverType != GKDriverType.RSR2_MAP4
&& driver.DriverType != GKDriverType.RSR2_MVK8 && driver.DriverType != GKDriverType.RSR2_RM_1 && driver.DriverType != GKDriverType.RSR2_OPKZ))
{
deviceGroup = new DeviceGroup();
deviceGroup.SerialNo = serialNo;
deviceGroups.Add(deviceGroup);
}
deviceGroup.Devices.Add(device);
}
}
}
else
{
break;
}
}
foreach (var deviceGroup in deviceGroups)
{
var firstDeviceInGroup = deviceGroup.Devices.FirstOrDefault();
if (deviceGroup.Devices.Count > 1 && firstDeviceInGroup != null)
{
GKDriver groupDriver = null;
if (firstDeviceInGroup.Driver.DriverType == GKDriverType.RSR2_AM_1)
{
if (deviceGroup.Devices.Count == 2)
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_AM_2);
else
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_AM_4);
}
if (firstDeviceInGroup.Driver.DriverType == GKDriverType.RSR2_MAP4)
{
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_MAP4_Group);
}
if (firstDeviceInGroup.Driver.DriverType == GKDriverType.RSR2_MVK8)
{
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_MVK8_Group);
}
if (firstDeviceInGroup.Driver.DriverType == GKDriverType.RSR2_RM_1)
{
if (deviceGroup.Devices.Count == 2)
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_RM_2);
else
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_RM_4);
}
if (firstDeviceInGroup.Driver.DriverType == GKDriverType.RSR2_OPKS)
{
groupDriver = GKManager.Drivers.FirstOrDefault(x => x.DriverType == GKDriverType.RSR2_OPSZ);
}
//.........这里部分代码省略.........
示例10: RetrievePerson
/// <summary>
/// Retrieves the guest.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="personData">The person data.</param>
/// <param name="workStation">The work station.</param>
/// <param name="eventType">Type of the event.</param>
/// <param name="personTypeList">The person type list.</param>
/// <param name="personList">The person list.</param>
/// <returns>
/// The person
/// </returns>
private static Person RetrievePerson(NotificationEvent message, Person personData, Workstation workStation, NotificationEventType eventType, List<PersonType> personTypeList, IList<PersonBase> personList)
{
var person = personList.Where(p => p.PersonId == message.PersonId).FirstOrDefault();
var task = Task.Run(async () => await PersonsService.RetrievePersonsBySearchText(workStation.Ship.ShipId, null, personTypeList, SearchType.PersonId, personId: message.PersonId, folioNumber: null));
task.Wait();
if (!task.IsCanceled && !task.IsFaulted)
{
personData = task.Result;
PersonBase retrievedPerson = null;
if (personTypeList.FirstOrDefault() == PersonType.Guest)
{
retrievedPerson = personData.Guests.FirstOrDefault().MapToPersonBase();
}
else if (personTypeList.FirstOrDefault() == PersonType.Crewmember)
{
retrievedPerson = personData.Crewmembers.FirstOrDefault().MapToPersonBase();
}
else if (personTypeList.FirstOrDefault() == PersonType.Visitor)
{
retrievedPerson = personData.Visitors.FirstOrDefault().MapToPersonBase();
}
if (personData != null)
{
MapPersonData(person, retrievedPerson, eventType);
if (person != null)
{
RetrievePhoto(person);
}
}
}
return personData;
}
示例11: LlenaForm
private void LlenaForm(DataRowView FilaSeleccionada)
{
List<PRODUCTO> listaProd = new List<PRODUCTO>();
listaProd = cPRODUCTO.ObtenerActivos().Where(x => x.PRO_ID == Convert.ToInt32(FilaSeleccionada["PRO_ID"])).ToList();
PRODUCTO oPRODUCTO = listaProd.FirstOrDefault();
cmbProducto.DataSource = listaProd;
cmbProducto.DisplayMember = "PRO_DESCRIPCION";
cmbProducto.ValueMember = "PRO_ID";
cmbProducto.SelectedIndex = 0;
txtCodigoBarra.Text = oPRODUCTO.PRO_BARRAS;
numCostoSinIva.Value = Convert.ToDecimal(FilaSeleccionada["PRECIOCOSTO_SINIVA"]);
numCostoConIva.Value = Convert.ToDecimal(FilaSeleccionada["PRECIOCOSTO_CONIVA"]);
cmbTipoIva.SelectedValue = (int)FilaSeleccionada["TIVA_ID"];
numCantidad.Value = Convert.ToDecimal(FilaSeleccionada["CANTIDAD"]);
numCantidadTotal.Value = Convert.ToDecimal(FilaSeleccionada["CANTIDAD_TOTAL"]);
txtPorcGanReal.Text = (FilaSeleccionada["PRO_MARGENGANANCIAREAL"]).ToString();
numPorcGanEstimada.Value = Convert.ToDecimal(FilaSeleccionada["PRO_MARGENGANACIAESTIMADA"]);
numPrecioVenta.Value = Convert.ToDecimal(FilaSeleccionada["PRECIO_VENTA"]);
numDescuento.Value = Convert.ToDecimal(FilaSeleccionada["PORCENTAJEDESCUENTO"]);
chkModificaPrecioVenta.Checked = (bool)FilaSeleccionada["MODIFICA_PRECIO_VENTA"];
chkBulto.Checked = (bool)FilaSeleccionada["ES_BULTO"];
numBulto.Value = Convert.ToDecimal(FilaSeleccionada["CANTIDAD_BULTO"]);
numBultoSinIva.Value = Convert.ToDecimal(FilaSeleccionada["PRECIOBULTO_SINIVA"]);
numBultoConIva.Value = Convert.ToDecimal(FilaSeleccionada["PRECIOBULTO_CONIVA"]);
numImpuesto.Value = Convert.ToDecimal(FilaSeleccionada["IMPUESTO"]);
txtCodigoBarra.Enabled = false;
cmbProducto.Enabled = false;
}
示例12: MapGuestInformation
/// <summary>
/// Maps the guest information.
/// </summary>
/// <param name="guests">The guests.</param>
/// <param name="personsStatusHistory">The persons status history.</param>
/// <param name="personStatusList">The person status list.</param>
private static void MapGuestInformation(GuestCollection guests, ListResult<PersonStatusHistory> personsStatusHistory, List<PersonStatus> personStatusList)
{
foreach (var guest in guests)
{
var item = personStatusList.FirstOrDefault(a => a.PersonId.ToString(CultureInfo.CurrentCulture).Equals(guest.GuestId));
var personStatusHistory = new PersonStatusHistory();
personStatusHistory.PersonId = guest.GuestId;
personStatusHistory.FirstName = guest.PersonalDetail.FirstName;
personStatusHistory.MiddleName = guest.PersonalDetail.MiddleName;
personStatusHistory.LastName = guest.PersonalDetail.LastName;
personStatusHistory.Gender = guest.PersonalDetail.Gender;
personStatusHistory.Age = guest.PersonalDetail.Age ?? 0;
personStatusHistory.LastEvent = item != null ? item.Status : guest.LastEvent;
personStatusHistory.LastDateTime = item != null ? item.StatusChangedDate : guest.LastDateTime;
personStatusHistory.PersonTypeId = CommonConstants.GuestTypeId;
personStatusHistory.ReservationNumber = guest.CruiseDetail.ReservationNumber;
personStatusHistory.Stateroom = guest.CruiseDetail.Stateroom;
personsStatusHistory.Items.Add(personStatusHistory);
}
}
示例13: SetListView
void SetListView()
{
lvMacStatus.Items.Clear();
if (this.m_AllStatusMonitoring.Count == 0)
{
return;
}
int tmp = 0;
if (this.m_AllStatusMonitoring.Count - m_iNowPage * this.m_iMaxCount > 0)
{
tmp = this.m_iMaxCount;
}
else
{
tmp = this.m_AllStatusMonitoring.Count - (m_iNowPage - 1) * this.m_iMaxCount;
}
ListViewItem lvitem;
List<ComboboxDataInfo> cdList = new List<ComboboxDataInfo>();
cdList.Add(new ComboboxDataInfo("待生產", CustEnum.ProjectStatus.SCHEDULE.ToString()));
cdList.Add(new ComboboxDataInfo("準備中", CustEnum.ProjectStatus.PREPARE.ToString()));
cdList.Add(new ComboboxDataInfo("準備超時", CustEnum.ProjectStatus.PREPARE_OT.ToString()));
cdList.Add(new ComboboxDataInfo("生產中", CustEnum.ProjectStatus.PROD_IN.ToString()));
cdList.Add(new ComboboxDataInfo("生產中停機", CustEnum.ProjectStatus.PROD_STOP.ToString()));
cdList.Add(new ComboboxDataInfo("生產中停機超時", CustEnum.ProjectStatus.PROD_STOP_OT.ToString()));
cdList.Add(new ComboboxDataInfo("完成", CustEnum.ProjectStatus.FINISH.ToString()));
cdList.Add(new ComboboxDataInfo("抽起", CustEnum.ProjectStatus.STOP.ToString()));
for (int i = (m_iNowPage - 1) * this.m_iMaxCount; i < (m_iNowPage - 1) * this.m_iMaxCount + tmp; i++)
{
lvitem = new ListViewItem();
lvitem.SubItems[0].Text = this.m_AllStatusMonitoring[i].MachineID;
lvitem.SubItems.Add(this.m_AllStatusMonitoring[i].ProjectNO);
lvitem.SubItems.Add(this.m_AllStatusMonitoring[i].SONO);
ComboboxDataInfo macStatc = cdList.FirstOrDefault(t => t.ValueMember == this.m_AllStatusMonitoring[i].MacStatus.Replace("狀態:", ""));
if (macStatc != null)
{
lvitem.SubItems.Add(macStatc.DisplayMember);
lvitem.ImageIndex = GetMacchineBMP(macStatc.ValueMember);
}
else
{
lvitem.SubItems.Add(this.m_AllStatusMonitoring[i].MacStatus);
lvitem.ImageIndex = GetMacchineBMP(this.m_AllStatusMonitoring[i].MacStatus);
}
lvitem.SubItems.Add(this.m_AllStatusMonitoring[i].MachineCaption);
lvitem.SubItems.Add(this.m_AllStatusMonitoring[i].choldTime.Replace("00:00:00", "未知"));
//lvitem.SubItems.Add(this.m_AllStatusMonitoring[i].ProdSpeed);
// lvitem.ImageIndex = GetImgIndex(this.m_AllStatusMonitoring[i].MacStatus);
lvMacStatus.Items.Add(lvitem);
}
}
示例14: CreateOrUpdateHook
protected void CreateOrUpdateHook(string owner, string repository, Site website)
{
string baseUri = website.GetProperty("repositoryuri");
string publishingUsername = website.GetProperty("publishingusername");
string publishingPassword = website.GetProperty("publishingpassword");
UriBuilder newUri = new UriBuilder(baseUri);
newUri.UserName = publishingUsername;
newUri.Password = publishingPassword;
newUri.Path = "/deploy";
string deployUri = newUri.ToString();
List<GithubRepositoryHook> repositoryHooks = new List<GithubRepositoryHook>();
InvokeInGithubOperationContext(() => { repositoryHooks = PSCmdlet.GithubChannel.GetRepositoryHooks(owner, repository); });
var existingHook = repositoryHooks.FirstOrDefault(h => h.Name.Equals("web") && new Uri(h.Config.Url).Host.Equals(new Uri(deployUri).Host));
if (existingHook != null)
{
if (!existingHook.Config.Url.Equals(newUri.ToString(), StringComparison.InvariantCultureIgnoreCase))
{
existingHook.Config.Url = deployUri;
InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.UpdateRepositoryHook(owner, repository, existingHook.Id, existingHook));
InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.TestRepositoryHook(owner, repository, existingHook.Id));
}
else
{
throw new Exception(Resources.LinkAlreadyEstablished);
}
}
else
{
GithubRepositoryHook githubRepositoryHook = new GithubRepositoryHook()
{
Name = "web",
Active = true,
Events = new List<string> { "push" },
Config = new GithubRepositoryHookConfig
{
Url = deployUri,
InsecureSsl = "1",
ContentType = "form"
}
};
InvokeInGithubOperationContext(() => { githubRepositoryHook = PSCmdlet.GithubChannel.CreateRepositoryHook(owner, repository, githubRepositoryHook); });
InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.TestRepositoryHook(owner, repository, githubRepositoryHook.Id));
}
}
示例15: MapVisitorInformation
/// <summary>
/// Maps the visitor information.
/// </summary>
/// <param name="visitors">The visitors.</param>
/// <param name="personsStatusHistory">The persons status history.</param>
/// <param name="personStatusList">The person status list.</param>
private static void MapVisitorInformation(VisitorCollection visitors, ListResult<PersonStatusHistory> personsStatusHistory, List<PersonStatus> personStatusList)
{
foreach (var visitor in visitors)
{
var item = personStatusList.FirstOrDefault(a => a.PersonId.ToString(CultureInfo.CurrentCulture).Equals(visitor.VisitorId));
var personStatusHistory = new PersonStatusHistory();
personStatusHistory.PersonId = visitor.VisitorId;
personStatusHistory.FirstName = visitor.PersonalDetail.FirstName;
personStatusHistory.MiddleName = visitor.PersonalDetail.MiddleName;
personStatusHistory.LastName = visitor.PersonalDetail.LastName;
personStatusHistory.Gender = visitor.PersonalDetail.Gender;
personStatusHistory.Age = visitor.PersonalDetail.Age ?? 0;
personStatusHistory.LastEvent = item != null ? item.Status : visitor.LastEvent;
////personStatusHistory.LastDateTime = item != null ? item.StatusChangedDate : visitor.LastDateTime;
personStatusHistory.PersonTypeId = CommonConstants.VisitorTypeId;
personsStatusHistory.Items.Add(personStatusHistory);
}
}