本文整理汇总了C#中IList.Single方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Single方法的具体用法?C# IList.Single怎么用?C# IList.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentPeriodId
public static int GetCurrentPeriodId(IList<Period> periods)
{
int currentMonth = DateTime.Now.Month;
switch (currentMonth)
{
case 1:
case 2:
case 3:
return periods.Single(p => p.NumberGym == 3).Id;
case 4:
case 5:
case 6:
return periods.Single(p => p.NumberGym == 4).Id;
case 7:
case 8:
case 9:
return periods.Single(p => p.NumberGym == 1).Id;
case 10:
case 11:
case 12:
return periods.Single(p => p.NumberGym == 2).Id;
default:
return 0;
}
}
示例2: ScramblePieces
public static IList<IJigsawPiece> ScramblePieces(IList<IJigsawPiece> pieces, int rows, int cols)
{
var random = new Random();
var temp = new List<KeyValuePair<int, int>>();
foreach (JigsawPieceBase originPiece in pieces)
{
int row = random.Next(0, rows);
int col = random.Next(0, cols);
while (temp.Exists(t => (t.Key == row) && (t.Value == col)))
{
row = random.Next(0, rows);
col = random.Next(0, cols);
}
temp.Add(new KeyValuePair<int, int>(row, col));
IJigsawPiece targetPiece = pieces.Single(p => p.OriginRow == row && p.OriginColumn == col);
//swap positions
var tempPoint = new Point(originPiece.Position.X, originPiece.Position.Y);
originPiece.Position = new Point(targetPiece.Position.X, targetPiece.Position.Y);
targetPiece.Position = tempPoint;
//Swap column and row numbers
int targetColumn = targetPiece.CurrentColumn;
int targetRow = targetPiece.CurrentRow;
targetPiece.CurrentColumn = originPiece.CurrentColumn;
targetPiece.CurrentRow = originPiece.CurrentRow;
originPiece.CurrentColumn = targetColumn;
originPiece.CurrentRow = targetRow;
}
return pieces;
}
示例3: GetPrimeCredit
public virtual VoucherInformation GetPrimeCredit(IList<VoucherInformation> vouchers)
{
int numberOfCredit = vouchers.Count(v => v.voucher.documentType == DocumentTypeEnum.Cr);
if (numberOfCredit == 1)
{
return vouchers.Single(v => v.voucher.documentType == DocumentTypeEnum.Cr);
}
else if (numberOfCredit > 1)
{
var creditVouchers = vouchers.Where(v => v.voucher.documentType == DocumentTypeEnum.Cr);
if (creditVouchers.Any(v => !string.IsNullOrEmpty(v.GetExtraAuxDom())))
{
return creditVouchers.Last(v => !string.IsNullOrEmpty(v.GetExtraAuxDom()));
}
else if (creditVouchers.Any(v => !string.IsNullOrEmpty(v.GetAuxDom())))
{
return creditVouchers.Last(v => !string.IsNullOrEmpty(v.GetAuxDom()));
}
else
{
return creditVouchers.Last();
}
}
return null;
}
示例4: GetCentralGeopoint
public static Geopoint GetCentralGeopoint(IList<Geopoint> geoPoints)
{
if (geoPoints.Count == 1)
{
return geoPoints.Single();
}
double x = 0;
double y = 0;
double z = 0;
foreach (var geopoint in geoPoints)
{
var latitude = geopoint.Position.Latitude * Math.PI / 180;
var longitude = geopoint.Position.Longitude * Math.PI / 180;
x += Math.Cos(latitude) * Math.Cos(longitude);
y += Math.Cos(latitude) * Math.Sin(longitude);
z += Math.Sin(latitude);
}
var total = geoPoints.Count;
x = x / total;
y = y / total;
z = z / total;
var centralLongitude = Math.Atan2(y, x);
var centralSquareRoot = Math.Sqrt(x * x + y * y);
var centralLatitude = Math.Atan2(z, centralSquareRoot);
return new Geopoint(new BasicGeoposition { Latitude = centralLatitude * 180 / Math.PI, Longitude = centralLongitude * 180 / Math.PI });
}
示例5: RetrievePlayerPerformances
private static IEnumerable<PlayerGameweekPerformance> RetrievePlayerPerformances(IEnumerable<int> playerIds, int gameweek, IList<Player> upToDatePlayers)
{
foreach (var playerId in playerIds)
{
int id = playerId;
var upToDatePlayer = upToDatePlayers.Single(x => x.Id == id);
var gameweekFixtures =
upToDatePlayer.PastFixtures.Where(x => x.GameWeek == gameweek);
yield return PerformanceMappingHelper.CreatePlayerPerformanceFromFixtures(upToDatePlayer.Id, upToDatePlayer.Name, upToDatePlayer.Position, gameweekFixtures);
}
}
示例6: GetJobDependencies
private string GetJobDependencies(Job current, string result, IList<Job> jobs)
{
if (result.Contains(current.Name))
return "";
if (string.IsNullOrEmpty(current.DependencyName))
return current.Name;
ThrowIfCircularDependencyFound(current);
return GetJobDependencies(jobs.Single(x => x.Name == current.DependencyName), result, jobs) + current.Name;
}
示例7: AddRecursive
private void AddRecursive(IList<NavigationNode> navigationNodes, NavigationNode toAdd)
{
if (navigationNodes.Contains(toAdd))
{
foreach (var node in toAdd.Children)
{
AddRecursive(navigationNodes.Single(x => x.Name == toAdd.Name).Children, node);
}
}
else
navigationNodes.Add(toAdd);
}
示例8: VerifyJavaModel
/// <summary>
/// Verifies that the resulting java model matches our expectations.
/// </summary>
private void VerifyJavaModel(
IList<JavaClass> expectedModel,
IList<JavaClass> actualModel)
{
Assert.Equal(expectedModel.Count, actualModel.Count);
foreach (var actualJavaClass in actualModel)
{
var expectedJavaClass = expectedModel
.Single(c => c.Type == actualJavaClass.Type);
VerifyJavaClass(expectedJavaClass, actualJavaClass);
}
}
示例9: HangmanGame
public HangmanGame(string solution)
{
Answer = solution;
Id = Guid.NewGuid();
_alphabet = "abcdefghijklmnopqrstuvwxyz ".ToArray()
.Select(letter => new Tile { Letter = letter.ToString() })
.ToArray();
_alphabet.Single(t => t.Letter == " ").State = TileState.Hit;
_solution = solution.ToArray()
.Select(letter => _alphabet.FirstOrDefault(t => t.Letter == letter.ToString()))
.ToArray();
}
示例10: SyncRoles
private void SyncRoles(IList<RoleCheckbox> checkboxes, IList<RoleNames> roles)
{
var selectedRoles = new List<RoleNames>();
foreach (var role in Database.Session.Query<RoleNames>())
{
var checkbox = checkboxes.Single(c => c.Id == role.Id);
checkbox.Role = role.Role;
if (checkbox.IsChecked)
selectedRoles.Add(role);
}
foreach (var toAdd in selectedRoles.Where(t => !roles.Contains(t)))
roles.Add(toAdd);
foreach (var toRemove in roles.Where(t => !selectedRoles.Contains(t)).ToList())
roles.Remove(toRemove);
}
示例11: AdjustTeamToGameweek
public Team AdjustTeamToGameweek(Team team, IList<Player> allUpToDatePlayers, int gameweek)
{
if (team == null) throw new ArgumentNullException("team");
if (gameweek < 1 || gameweek > 38) throw new ArgumentException("gameweek");
if (allUpToDatePlayers == null) throw new ArgumentNullException("allUpToDatePlayers");
_logger.Log(Tag.Adjusting, string.Concat("Adjusting team to gameweek ", gameweek));
var updatedTeam = new Team();
foreach (var playerInTeam in team.Players)
{
//find player that is up to date to adjust
Player inTeam = playerInTeam;
var playerToAdjust = allUpToDatePlayers.Single(x => x.Id == inTeam.Id);
//bring them back to the current gameweek
var adjustedPlayer = AdjustPlayer(playerToAdjust, gameweek);
if(adjustedPlayer.NowCost != playerInTeam.NowCost)
{
_logger.Log(Tag.Adjusting, string.Format("{0} value has {1} from {2} to {3}", playerInTeam.Name, adjustedPlayer.NowCost > playerInTeam.NowCost ? "increased" : "decreased", playerInTeam.NowCost.ToMoney(), adjustedPlayer.NowCost.ToMoney()));
}
//now copy over anything that is special about a player being in your team
//todo: check this is correct when we find out property for purchase cost
adjustedPlayer.OriginalCost = playerInTeam.OriginalCost;
updatedTeam.Players.Add(adjustedPlayer);
}
//now switch over captains
updatedTeam.Captain = updatedTeam.Players.Single(p => p.Id == team.Captain.Id);
updatedTeam.ViceCaptain = updatedTeam.Players.Single(p => p.Id == team.ViceCaptain.Id);
return updatedTeam;
}
示例12: RoomViewModel
public RoomViewModel(MainViewModel mainViewModel, Room room, IList<User> users)
: base(true)
{
Description = room;
MainViewModel = mainViewModel;
Messages = new ObservableCollection<MessageViewModel>();
allInRoom = new UserViewModel(new User("Все в комнате", Color.Black), this);
messageIds = new HashSet<long>();
Users = new ObservableCollection<UserViewModel>(users == null
? Enumerable.Empty<UserViewModel>()
: room.Users.Select(user => new UserViewModel(users.Single(u => u.Equals(user)), this)));
SendMessageCommand = new Command(SendMessage, Obj => ClientModel.Client != null);
PastReturnCommand = new Command(PastReturn);
AddFileCommand = new Command(AddFile, Obj => ClientModel.Client != null);
InviteInRoomCommand = new Command(InviteInRoom, Obj => ClientModel.Client != null);
KickFromRoomCommand = new Command(KickFromRoom, Obj => ClientModel.Client != null);
ClearSelectedMessageCommand = new Command(ClearSelectedMessage, Obj => ClientModel.Client != null);
MainViewModel.AllUsers.CollectionChanged += AllUsersCollectionChanged;
NotifierContext.ReceiveMessage += ClientReceiveMessage;
NotifierContext.RoomRefreshed += ClientRoomRefreshed;
}
示例13: Sync
public static void Sync(IList<RoleCheckBox> checkBoxes, IList<Role> userRoles)
{
var selectedRoles = new List<Role>();
foreach (var role in Database.Session.Query<Role>())
{
var checkBox = checkBoxes.Single(c => c.Id == role.Id);
checkBox.Name = role.Name;
if (checkBox.IsChecked)
selectedRoles.Add(role);
}
foreach (var roleToAdd in selectedRoles.Where(sr => !userRoles.Contains(sr)))
{
userRoles.Add(roleToAdd);
}
foreach (var roleToRemove in userRoles.Where(cr => !selectedRoles.Contains(cr)).ToList())
{
userRoles.Remove(roleToRemove);
}
}
示例14: UpdateFromSeriesEditor
public virtual void UpdateFromSeriesEditor(IList<Series> editedSeries)
{
var allSeries = GetAllSeries();
foreach(var series in allSeries)
{
//Only update parameters that can be changed in MassEdit
var edited = editedSeries.Single(s => s.SeriesId == series.SeriesId);
series.QualityProfileId = edited.QualityProfileId;
series.Monitored = edited.Monitored;
series.SeasonFolder = edited.SeasonFolder;
series.BacklogSetting = edited.BacklogSetting;
series.Path = edited.Path;
}
_database.UpdateMany(allSeries);
}
示例15: Process
public async Task<IList<DiagnosisResultDTO>> Process(IList<FuzzySymptomDTO> symptomes)
{
var symptomIds = symptomes.Select(s => s.SymptomId).ToArray();
var diagnosesRepo = _unitOfWork.RepositoryAsync<Diagnosis>();
var diagnosis = diagnosesRepo.Query(d => d.Symptoms.Any(s => symptomIds.Any(id => id == s.SymptomId))).Select().Distinct().OrderBy(d => d.Id).ToList();
var diagnosesIds = diagnosis.Select(d => d.Id).ToArray();
var IS = await InitFuzzyEngineDiagnosis(symptomIds, diagnosesIds);
var symptomRepo = _unitOfWork.RepositoryAsync<Symptom>();
var symptoms = await symptomRepo.Queryable().Where(s => symptomIds.Any(sId => sId == s.Id)).ToListAsync();
foreach(var s in symptoms)
{
var fuzzySymptom = symptomes.Single(fs => fs.SymptomId == s.Id);
var fuzzy = fuzzySymptom.FuzzySet != null ? fuzzySymptom.FuzzySet : SymptomFuzzySet.Common;
var average = (fuzzy.RightLimit + fuzzy.LeftLimit) / 2;
try
{
IS.SetInput(s.Name, average);
}
catch(Exception exc)
{
}
}
var result = new List<DiagnosisResultDTO>();
var evaluate = IS.Evaluate("Diagnosis");
var i = 0;
foreach (var diagnoses in diagnosis)
{
i++;
var predel = new Tuple<int, int>(i > 1 ? (i - 1) * 100 : -1, i * 100);
if(predel.Item1 <= (int)evaluate && predel.Item2 >= (int)evaluate)
{
result.Add(new DiagnosisResultDTO
{
DiagnosisId = diagnoses.Id,
DiagnosisName = diagnoses.DisplayName,
Coefficient = 100//TODO:
});
break;
}
//try
//{
// result.Add(new DiagnosisResultDTO {
// DiagnosisId = diagnoses.Id,
// DiagnosisName = diagnoses.DisplayName,
// Coefficient = IS.Evaluate(diagnoses.Name)
// });
//}
//catch(Exception exc)
//{
//}
}
return result;
}