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
bro
Gradebook
look at this, soaches
MVC Learning
Lambdas
D12
Contravariance
Homework4
Enum Extension
Changing asp net user password