Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Метод catch b try в словарях
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here Console.WriteLine("Hello, world!"); Dictionary <int, Person> dic= new Dictionary <int, Person>(2); dic.Add(1, new Person() {Name ="aa"}); dic.Add(2, new Person() {Name ="bb"}); // dic.Add(4,"bb"); foreach (KeyValuePair<int, Person> keyvalue in dic) { try { switch(keyvalue.Key) { case 1: Console.WriteLine(keyvalue.Value.Name); break; case 2: Console.WriteLine(keyvalue.Value); break; } } catch (ArgumentException) { Console.WriteLine("Err"); } } } } public class Person { public string Name {get; set;} } }
run
|
edit
|
history
|
help
0
Test
Why do my posts keep getting deleted?
string.Format example
Fórum Parallel Threads ( With Much Fun )
Konsol Üçgen Çizimi
ee
Interviews
test
EFCXAXS
struc t