本文整理汇总了C#中HashSet.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.ElementAt方法的具体用法?C# HashSet.ElementAt怎么用?C# HashSet.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.ElementAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add
public void add()
{
Assert.Throws<ArgumentNullException>(() => CollectionsExtensions.Add(null, Enumerable.Empty<object>()));
Assert.Throws<ArgumentNullException>(() => new object[0].Add(null));
ICollection<string> first = new HashSet<string> {"first"};
ICollection<string> second = new List<string> {"second"};
first.Add(second);
Assert.Equal(2, first.Count);
Assert.Equal("first", first.ElementAt(0));
Assert.Equal("second", first.ElementAt(1));
}
示例2: Main
static void Main()
{
bool found = false;
int n = int.Parse(Console.ReadLine());
var numbers = new HashSet<int>(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
int numOfSubsets = 1 << numbers.Count;
for (int i = 0; i < numOfSubsets; i++)
{
List<int> subset = new List<int>();
int pos = numbers.Count - 1;
int b = i;
while (b > 0)
{
if ((b & 1) == 1)
subset.Add(numbers.ElementAt<int>(pos));
b >>= 1;
pos--;
}
if ((subset.Sum() == n) && (subset.Count != 0))
{
found = true;
Console.WriteLine(string.Join(" + ", subset) + " = {0}", n);
}
}
if (!found)
Console.WriteLine("No matching subsets.");
}
示例3: GetNextTarget
public override Unit GetNextTarget(HashSet<Unit> units)
{
if (units.Count > 0) {
return units.ElementAt(0);
}
return null;
}
示例4: GetAllSubsets
static List<HashSet<int>> GetAllSubsets(HashSet<int> s)
{
if (s.Count == 0)
return null;
s = new HashSet<int>(s);//Copy the set so the original one will not be modified.
int element = s.ElementAt(0);
s.Remove(element);
List<HashSet<int>> list = GetAllSubsetsHelper(element, s);
return list;
}
示例5: MockKomorek
public void AktualizatorBrzeżnościRogówOdpowiednioJePrzypisuje(int indeksInicjatora,
BrzeznoscRogu spodziewanaBrzeznoscR1, BrzeznoscRogu spodziewanaBrzeznoscR2,
BrzeznoscRogu spodziewanaBrzeznoscR3, BrzeznoscRogu spodziewanaBrzeznoscR4, BrzeznoscRogu spodziewanaBrzeznoscR5)
{
_komorki = MockKomorek();
_rogi = MockRogow(_komorki);
IMapa mapa = MockKlasyMapa(_komorki, _rogi);
IKomorka inicjator = _komorki.ElementAt(indeksInicjatora);
var rozdzielacz = new RozdzielaczMorzIJezior(inicjator)
{
Nastepnik = new AktualizatorBrzeznosciRogow()
};
mapa.ZastosujPrzetwarzanie(rozdzielacz);
_rogi.ElementAt(0).Dane.Brzeznosc.ShouldEqual(spodziewanaBrzeznoscR1);
_rogi.ElementAt(1).Dane.Brzeznosc.ShouldEqual(spodziewanaBrzeznoscR2);
_rogi.ElementAt(2).Dane.Brzeznosc.ShouldEqual(spodziewanaBrzeznoscR3);
_rogi.ElementAt(3).Dane.Brzeznosc.ShouldEqual(spodziewanaBrzeznoscR4);
_rogi.ElementAt(4).Dane.Brzeznosc.ShouldEqual(spodziewanaBrzeznoscR5);
}
开发者ID:pslusarczyk,项目名称:praca_magisterska,代码行数:21,代码来源:TestyPrzetwarzaczyZwiazanychZeZbiornikamiWodnymi.cs
示例6: Main
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
var numbers = new HashSet<int>(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
List<List<int>> unsorted = new List<List<int>>();
bool found = false;
int numOfSubsets = 1 << numbers.Count;
for (int i = 0; i < numOfSubsets; i++)
{
List<int> subset = new List<int>();
int pos = numbers.Count - 1;
int bitmask = i;
while (bitmask > 0)
{
if ((bitmask & 1) == 1)
{
subset.Add(numbers.ElementAt<int>(pos));
}
bitmask >>= 1;
pos--;
}
if ((subset.Sum() == n) && (subset.Count != 0))
{
found = true;
subset.Sort();
unsorted.Add(subset);
}
}
List<List<int>> results = unsorted.OrderBy(x => x.Count).ThenBy(x => x.ElementAt(0)).ToList();
if (found)
{
foreach (List<int> list in results)
{
Console.WriteLine(string.Join(" + ", list) + " = " + n);
}
}
else
{
Console.WriteLine("No matching subsets.");
}
}
示例7: buttonOk_Click
private void buttonOk_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
SelectedTable = (ITable)listBox1.SelectedItem;
HashSet<ITable> tables = new HashSet<ITable>();
foreach (ListViewItem item in listViewColumns.CheckedItems)
tables.Add(((IColumn)item.Tag).Parent);
StringBuilder sb = new StringBuilder(100);
for (int i = 0; i < tables.Count; i++)
{
sb.Append(tables.ElementAt(i).Name);
if (i < tables.Count - 1)
sb.Append(", ");
}
if (MessageBox.Show(this, string.Format("Delete all entities currently mapped to this tables [{0}]?", sb), "Delete mapped entities?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
foreach (var table in tables)
{
var entities = table.MappedEntities().ToList();
for (int i = entities.Count - 1; i >= 0; i--)
{
var entity = entities[i];
entity.DeleteSelf();
}
}
foreach (ListViewItem item in listViewColumns.CheckedItems)
{
IColumn column = (IColumn)item.Tag;
Property newProperty = Controller.MappingLayer.OneToOneEntityProcessor.CreatePropertyFromColumn(column);
newProperty.Name = newProperty.Name.GetNextName(Entity.Properties.Select(p => p.Name));
Entity.AddProperty(newProperty);
newProperty.SetMappedColumn(column);
}
//if (checkBoxAddReferences.Checked)
//{
// var mappedEntities = SelectedTable.MappedEntities();
// if (mappedEntities.Count() == 1)
// {
// if (mappedEntities.ElementAt(0).MappedTables().Count() == 1)
// }
//}
}
Close();
}
示例8: Main
static void Main(string[] args)
{
String text = "This is a simple text that count unique words . And this is the text that must be checked";
HashSet<String> words = new HashSet<string>();
String[] differentWords = text.Split(' ');
for(int i=0;i<differentWords.Length;i++)
{
words.Add(differentWords[i]);
}
Console.WriteLine("Here are all the unique words : ");
for(int i=0;i<words.Count;i++)
{
Console.WriteLine(words.ElementAt(i));
}
}
示例9: Main
static void Main(string[] args)
{
string text = "Example test example list Example is here";
HashSet<string> uniqueWords = new HashSet<string>();
string[] storage = text.ToLower().Split(' ');
for (int i = 0; i < storage.Length; i++)
{
uniqueWords.Add(storage[i]);
}
for (int i = 0; i < uniqueWords.Count; i++)
{
Console.WriteLine(uniqueWords.ElementAt(i));
}
}
示例10: GetNodes
/// <summary>
/// Get node collection from dataGridView
/// </summary>
/// <returns>HashSet of nodes</returns>
public HashSet<Node> GetNodes()
{
HashSet<Node> Nodes = new HashSet<Node>();
// Enlist all nodes
for (int row = 0; row < dataTable.Rows.Count; row++)
Nodes.Add(new Node((string)dataTable.Rows[row][0], (int)dataTable.Rows[row][1]));
// Create dependencies
for (int row = 0; row < dataTable.Rows.Count; row++)
if (dataTable.Rows[row][2] != null)
foreach (string dependency in dataTable.Rows[row][2].ToString().Split(separators, StringSplitOptions.RemoveEmptyEntries))
Nodes.ElementAt(row).Dependencies.Add(Nodes.Single(new Func<Node, bool>(delegate(Node node)
{
return node.ID == dependency;
})));
return Nodes;
}
示例11: GetWords
public string GetWords()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
TrollResponse troll = new TrollResponse();
Random rand = new Random();
/** choose a text file at random to give to the client **/
int textFilename = rand.Next(0, 5);
string text = File.ReadAllText("../../Text/" + textFilename + ".txt");
/** **/
/** split text on different punctuations **/
char[] separators = {'.', ' ', ',', '!', ';', '-'};
string[] wordsInText = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
/** **/
/** create a set of unique words in the text **/
HashSet<string> uniqueWords = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase);
foreach (string word in wordsInText)
{
uniqueWords.Add(word);
}
/** **/
int len = uniqueWords.Count;
troll.Text = text;
/** if there is only one unique word in text exclude word list will be empty **/
if (len == 1)
{
return serializer.Serialize(troll);
}
/** **/
/** select words to be excluded from count at random **/
int excludeLen = rand.Next(0, len - 1);
HashSet<string> excludeList = new HashSet<string>();
for (int i = 0; i < excludeLen; i++)
{
excludeList.Add(uniqueWords.ElementAt(rand.Next(0 , len - 1)));
}
troll.Exclude = excludeList.ToArray();
/** **/
return serializer.Serialize(troll);
}
示例12: ListBookings
public ListBookings(Welcome welcomeForm, OdbcConnection odbcConnection, HashSet<BookingInformation> bookings)
: this()
{
objectWelcomeForm = welcomeForm;
objectOdbcConnection = odbcConnection;
bookingsListView.Columns.Add("Guest ID");
bookingsListView.Columns.Add("First Name");
bookingsListView.Columns.Add("Last Name");
bookingsListView.Columns.Add("Phone");
bookingsListView.Columns.Add("CheckIn Date");
bookingsListView.Columns.Add("CheckOut Date");
bookingsListView.Columns.Add("Room Number");
bookingsListView.Columns.Add("Booking Status");
bookingsListView.Columns[0].Width = 100;
bookingsListView.Columns[1].Width = 125;
bookingsListView.Columns[2].Width = 125;
bookingsListView.Columns[3].Width = 100;
bookingsListView.Columns[4].Width = 80;
bookingsListView.Columns[5].Width = 80;
bookingsListView.Columns[6].Width = 80;
bookingsListView.Columns[7].Width = 100;
//bookingsListBox.Items.Add(lv);
for(int i= 0; i<bookings.Count; i++)
{
string[] listColumns = new string[8];
listColumns[0] = bookings.ElementAt(i).bookedGuest.guestId;
listColumns[1] = bookings.ElementAt(i).bookedGuest.firstName;
listColumns[2] = bookings.ElementAt(i).bookedGuest.lastName;
listColumns[3] = bookings.ElementAt(i).bookedGuest.phone;
listColumns[4] = bookings.ElementAt(i).checkInDate.ToShortDateString();
listColumns[5] = bookings.ElementAt(i).checkOutDate.ToShortDateString();
listColumns[6] = bookings.ElementAt(i).bookedRoom.roomNumber;
listColumns[7] = bookings.ElementAt(i).status;
ListViewItem li = new ListViewItem(listColumns);
if (i % 2 == 0)
{
li.BackColor = Color.Gainsboro;
}
bookingsListView.Items.Add(li);
}
}
示例13: GetRhythm
/// <summary>
/// Метод возвращает массив, описывающий ритм
/// </summary>
/// <param name="segmentsCount">Количество долей в такте (количество нот и пауз)</param>
/// <param name="notesCount">Количество звучащих нот</param>
/// <returns></returns>
public static int[] GetRhythm(int segmentsCount, int notesCount)
{
HashSet<int> set = new HashSet<int>();
for (int i = 0; i < segmentsCount; i++)
{
set.Add(i);
}
int[] rhythm = new int[segmentsCount];
Random rand = new Random();
for (int i = 0; i < notesCount; i++)
{
int pos = rand.Next(0, segmentsCount);
int position = set.ElementAt(pos);
rhythm[position] = 1;
set.Remove(position);
segmentsCount--;
}
return rhythm;
}
示例14: Chunk
public Chunk(Vector3 position)
{
this.BlockPositions = new Block[ChunkSize, ChunkSize, ChunkSize];
this.Position = position * ChunkSize;
this.uniqueBlocks = new HashSet<Block>();
this.uniqueBlocks.Add(new Block("checkerboard"));
this.uniqueBlocks.Add(new Block("stone"));
Random rnd = new Random();
for (int x = 0; x < ChunkSize; x++)
{
for (int z = 0; z < ChunkSize; z++)
{
int maxY = rnd.Next(1, 4);
for (int y = 0; y <= maxY; y++)
{
this.BlockPositions[x, y, z] = uniqueBlocks.ElementAt(0);
}
}
}
this.Mesh = GenerateMesh();
this.Effects = new HashSet<Effect>();
foreach (Block b in this.uniqueBlocks)
{
BasicEffect effect = new BasicEffect(Game1.Instance.GraphicsDevice);
effect.TextureEnabled = true;
effect.Texture = b.Texture;
this.Effects.Add(effect);
b.Effects.Add(effect);
}
}
示例15: GetAllSubsetsHelper
static List<HashSet<int>> GetAllSubsetsHelper(int n, HashSet<int> s)
{
List<HashSet<int>> list = new List<HashSet<int>>();
if (s.Count == 0)
{
list.Add(new HashSet<int>());
HashSet<int> withN = new HashSet<int>();
withN.Add(n);
list.Add(withN);
return list;
}
int element = s.ElementAt(0);
s.Remove(element);
list = GetAllSubsetsHelper(element,s);
List<HashSet<int>> secondList = new List<HashSet<int>>();
for(int i = 0;i<list.Count;i++)
{
HashSet<int> newSet = new HashSet<int>(list.ElementAt<HashSet<int>>(i));
newSet.Add(n);
secondList.Add(newSet);
}
list.AddRange(secondList);
return list;
}