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
TestCodec1
Switch on String
30272 Program Ex5_1 if else_2
30272 Program Ex3
172
dgh ret ertfh fhf hft85487
Ashraf
Reflekcja assembly, instancja i metoda
HelloWorld
Jai