Programátorská hádanka: this = new Foo();
Dokážete si představit situaci, kdy následující kód půjde zkompilovat a poběží? [code lang=“csharp“ light=“true“] public void Reset() { this = new Foo(); } [/code] Řešení: https://dotnetfiddle.net/JheuMu.
Štítek · 8 článků
Dokážete si představit situaci, kdy následující kód půjde zkompilovat a poběží? [code lang=“csharp“ light=“true“] public void Reset() { this = new Foo(); } [/code] Řešení: https://dotnetfiddle.net/JheuMu.
Tato metoda obvykle vrací false. Napadne vás uspořádání, kdy vrátí true? [code lang=“csharp“ light=“true“] static bool Test(out int x, out int y) { x = 123; y = 45; return…
Co bude výstupem? [code lang=“csharp“ light=“true“] try { try { throw new Exception("A"); } catch { throw new Exception("B"); } finally { throw new Exception("C"); } } catch…
Přijde vám na následujícím kódu něco divného? [sourcecode language=“csharp“ padlinenumbers=“true“ gutter=“true“ light=“false“] public void DoSomething(MyClass firstParameter) { if (firstParameter == null) { throw new ArgumentNullException(nameof(firstParameter), "My message."); }…
Co myslíte, že je v Member v jednotlivých případech? [sourcecode language=“csharp“ padlinenumbers=“true“ light=“true“] class BaseClass<T> { public static string Member; } class DerivedClass1 : BaseClass<int> { } class…
Jaký je rozdíl v prapagaci výjimky z bloku catch: [sourcecode language=“csharp“ light=“true“] try { … } catch (Exception e) { throw; } [/sourcecode] versus [sourcecode language=“csharp“ light=“true“] try…
Jaký je rozdíl v zachytávání výjimek při použití typu výjimky Exception [sourcecode language=“csharp“ light=“true“] try { … } catch (Exception e) { … } [/sourcecode] a bez použití…
Víte co znamená @ v následujícím bloku kódu? [sourcecode language=“csharp“ light=“true“] ICollection @is = dataSource as ICollection; if (@is != null) { this.Items.Capacity = @is.Count + this.Items.Count; }…