static void Main(string[] args) { Console.WriteLine($"Press 'a' or 'b'. Everything else finishes the program."); ConsoleKeyInfo info = Console.ReadKey(); while (true) { if (info.KeyChar != 'a' && info.KeyChar != 'b') { Console.WriteLine($""); Console.WriteLine($"You typed {info.Key} so the program is finished."); Console.WriteLine($"The hash code is {info.GetHashCode()}"); break; } else { Console.WriteLine($""); Console.WriteLine($"You typed {info.Key}."); Console.WriteLine($"The hash code is {info.GetHashCode()}"); } info = Console.ReadKey(); } }
public void Equals_SameData(ConsoleKeyInfo cki) { ConsoleKeyInfo other = cki; // otherwise compiler warns about comparing the instance with itself Assert.True(cki.Equals((object)other)); Assert.True(cki.Equals(other)); Assert.True(cki == other); Assert.False(cki != other); Assert.Equal(cki.GetHashCode(), other.GetHashCode()); }
} //end of the function public void GeneratePageView(List <string> data) { Console.Clear(); int currentPageIndex = 0; int total = data.Count; while (true) { Console.WriteLine( $"---------------------------- Đang hiển thị trang {currentPageIndex + 1} trên tổng số {total} trang ----------------------------"); Console.WriteLine(data[currentPageIndex]); Console.WriteLine( "--------------------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("ấn > để next, ấn < để back, ấn esc để exit"); ConsoleKeyInfo keyInfo = Console.ReadKey(true); int charKey = keyInfo.GetHashCode(); //get ascii code of keyboard character entered if (charKey == 46) // 62 is ascii code of '.' or > { Console.Clear(); currentPageIndex++; if (currentPageIndex > total - 1) { currentPageIndex = 0; continue; } } if (charKey == 44) //60 is ascii code of comma ',' or < { Console.Clear(); currentPageIndex--; if (currentPageIndex < 0) { currentPageIndex = total - 1; continue; } } if (charKey == 27) //27 is ascii code of esc { break; } } }
public void HashCodeNotEquals_DifferentData(ConsoleKeyInfo left, ConsoleKeyInfo right) { Assert.NotEqual(left.GetHashCode(), right.GetHashCode()); }