-
MY PROJECTS
-
Recent Posts
- SQL.How can you compare two nullable values safely, and how does IS DISTINCT FROM differ from <>?
- SQL.How are NULL values ordered by ORDER BY, how do defaults differ between databases, and how can you control their placement?
- SQL.How does NULL propagate through arithmetic expressions, and how can COALESCE and NULLIF help handle missing values and division by zero?
- SQL.How does NULL affect join conditions, and why can filtering the right-hand table in WHERE remove unmatched rows from a LEFT JOIN?
- SQL.How do GROUP BY and DISTINCT treat NULL values, even though NULL = NULL evaluates to UNKNOWN?
- SQL.How do aggregate functions handle NULL, and what is the difference between COUNT(*), COUNT(column), and COUNT(DISTINCT column)?
- SQL.How does NULL affect IN and NOT IN, and why can NOT EXISTS be a safer choice when a subquery returns nullable values?
- SQL.How do WHERE, HAVING, and CHECK constraints treat conditions that evaluate to UNKNOWN?
- SQL.Why do column = NULL and column <> NULL not work as expected, and when should you use IS NULL and IS NOT NULL?
- SQL.What is SQL’s three-valued logic (TRUE, FALSE, UNKNOWN), and how do AND, OR, and NOT behave with UNKNOWN?
- ChromeDevTools.Watch all failed requests
- SQL.What are domain types (or constraints on data types), and how do they help enforce data correctness?
- SQL.How does SQL handle comparisons between different data types (for example, string vs number), and why is this dangerous?
- SQL.What is the difference between DATE, TIME, TIMESTAMP, and TIMESTAMPTZ, and which one should be used for business events?
- SQL.How do numeric types like INTEGER, BIGINT, DECIMAL, and FLOAT differ in terms of precision and use cases?
- SQL.What problems can arise from implicit type casting in SQL, and how can it affect indexes?
- SQL.How does NULL differ from 0, an empty string, or FALSE in SQL?
- SQL.What is the difference between CHAR, VARCHAR, and TEXT, and when would you choose each?
- SQL.What is MVCC ?
- SQL.What is AutoVacuum Postgres ?
Categories
- Aptana
- Azure
- C#
- DataSnap
- DBExpress
- Delphi
- Delphi и сети
- Delphi. Язык программирования
- ExtJS
- FastReport
- FireDAC
- FireMonkey
- GIT
- ICS
- IDE
- IIS
- Indy
- InnoSetup
- javascript
- jQuery
- JSON
- LiveBindings
- MSHTML
- MySQL
- PHP
- REST
- Ribbons
- SMS
- SQL инструкции
- SVN
- TRichView
- UniGui
- WebBroker
- WinAPI
- Windows
- Алгоритмы
- Без рубрики
- Деревья
- Ищу ответ
- Компонентостроение
- Мои компоненты
- Начальный уровень
- Обработка исключений
- Парсинг
- Потоки(Threads)
- Регулярные выражения
- Тестирование приложений
Category Archives: C#
C#. Interfaces Hierarchy
123
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InterfaceHierarchy { class Program { static void Main(string[] args) { SomeClass sc = new SomeClass(); sc.Draw(); sc.Draw1(123); sc.Draw2(123); IAdvancedDraw ifAdvDraw; ifAdvDraw = (IAdvancedDraw)sc; sc.Draw(); sc.Draw1(123); sc.Draw2(123); } } public class SomeClass : IAdvancedDraw { public void Draw() { // throw new NotImplementedException(); } public void Draw1(int someParam) { //throw new NotImplementedException(); } public void Draw2(int someParam) { //throw new NotImplementedException(); } } // interfaces public interface IDrawable { void Draw(); } public interface IAdvancedDraw : IDrawable { void Draw1(int someParam); void Draw2(int someParam); } } |
Posted in C#
Comments Off on C#. Interfaces Hierarchy
C#. Explicit interfaces implementation
123
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExplicitInterfaces { class Program { static void Main(string[] args) { SomeClass sc = new SomeClass(); sc.Draw(); // accessible as public SomeClass2 sc2 = new SomeClass2(); // sc2.Draw(); // not accessible as public IDrawToForm intfForm = (IDrawToForm)sc2; intfForm.Draw(); } } public interface IDrawToForm { void Draw(); } public interface IDrawToMemory { void Draw(); } public interface IDrawToPrinter { void Draw(); } public class SomeClass: IDrawToForm, IDrawToMemory, IDrawToPrinter { public void Draw() { /*123*/ } // << problem! One implementation for all interfaces } public class SomeClass2 : IDrawToForm, IDrawToMemory, IDrawToPrinter { void IDrawToPrinter.Draw() // private access { /*some Implementation1*/ //throw new NotImplementedException(); } void IDrawToMemory.Draw() // private access { /*some Implementation2*/ //throw new NotImplementedException(); } void IDrawToForm.Draw() // private access { /*some Implementation3*/ //throw new NotImplementedException(); } } } |
Posted in C#
Comments Off on C#. Explicit interfaces implementation
C#. Array of interfaced objects
123
|
1 2 |
IPointy[] myPointObjs = { new Hexagon(), new Knife(), new Triangle() }; foreach (var i in myPointObjs){ Console.WriteLine(i.Points); } |
full example
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Interace { class Program { static IPointy FindFirstPointyShape(Shape[] shapes) { foreach (var s in shapes) { if (s is IPointy) { return s as IPointy; } } return null; } static void Main(string[] args) { IPointy[] myPointObjs = { new Hexagon(), new Knife(), new Triangle() }; foreach (var i in myPointObjs){ Console.WriteLine(i.Points); } Shape[] shapes = { new Triangle("Triangle"), new Hexagon("Hexagon"), new Circle("Circle") }; IPointy firstPointyItem = FindFirstPointyShape(shapes); Console.WriteLine("Item has {0} points", firstPointyItem.Points); Triangle t = new Triangle("Triangle"); t.Draw(); Hexagon h = new Hexagon("Hexagon"); h.Draw(); Circle c = new Circle("Circle"); c.Draw(); // another example for (int i = 0; i < shapes.Length; i++) { if (shapes[i] is IPointy) Console.WriteLine("Points in " + shapes[i].Name + " " + (shapes[i] as IPointy).Points); else Console.WriteLine("Ipointy not supported in " + shapes[i].Name); } Circle c1 = new Circle("Circle"); IPointy itf = null; try { itf = (IPointy)c1; } catch (InvalidCastException e) { Console.WriteLine(e.Message); } Console.ReadLine(); } // base class public class Shape { public string Name { get; set; } public Shape(string name) { Name = name; } public Shape() { } public virtual void Draw() { } } //declaring interface public interface IPointy { byte Points { get; } } // another one public interface IDraw3D { void Draw3D(); } // Triangle - derived from shape and implementing IPointy public class Triangle : Shape, IPointy { public Triangle() { } public Triangle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 3; } } } // Hexagon - derived from shape and implementing IPointy public class Hexagon : Shape, IPointy, IDraw3D { public Hexagon() { } public Hexagon(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 6; } } // << another implementation of IPointy public void Draw3D() { Console.WriteLine("Drawing Hexagon in 3D"); } } // // Circle - derived from shape and NOT implementing IPointy public class Circle : Shape { public Circle() { } public Circle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } } public class ThreeDCircle : Circle, IDraw3D { public void Draw3D() { Console.WriteLine("Draw Circle in 3D"); } } // knife public class Knife : Shape, IPointy { public Knife() { } public Knife(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 4; } } // << another implementation of IPointy } // fork public class Fork : Shape, IPointy { public Fork() { } public Fork(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 1; } } // << another implementation of IPointy } } } |
Posted in C#
Comments Off on C#. Array of interfaced objects
C#. Interface as return value
123
|
1 2 3 4 5 6 7 8 9 |
static IPointy FindFirstPointyShape(Shape[] shapes) { foreach (var s in shapes) { if (s is IPointy) { return s as IPointy; } } return null; } |
In Main
|
1 2 3 |
Shape[] shapes = { new Triangle("Triangle"), new Hexagon("Hexagon"), new Circle("Circle") }; IPointy firstPointyItem = FindFirstPointyShape(shapes); Console.WriteLine("Item has {0} points", firstPointyItem.Points); |
Posted in C#
Comments Off on C#. Interface as return value
C#. Interface as method Param
123
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IntfAsMethodParam { class Program { static void Main(string[] args) { Shape[] shapes = { new Triangle("Triangle"), new Circle("Circle") }; foreach (var shape in shapes) { if (shape is IDraw3D) { SomeMethod((IDraw3D)shape); } // <<< applying method } } static void SomeMethod(IDraw3D itf3d) // <<< IDraw3D interface as param { Console.WriteLine("3d drawing "); itf3d.Draw3D(); } // base class public class Shape { public string Name { get; set; } public Shape(string name) { Name = name; } public Shape() { } public virtual void Draw() { } } // Circle - derived from shape and NOT implementing IPointy public class Circle : Shape,IDraw3D { public Circle() { } public Circle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public void Draw3D() { Console.WriteLine("3D Drawing Shape name is {0}", this.Name); } } // Triangle - derived from shape and implementing IPointy public class Triangle : Shape, IPointy { public Triangle() { } public Triangle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 3; } } } //declaring interface public interface IDraw3D { void Draw3D(); } //declaring interface public interface IPointy { byte Points { get; } } } } |
Posted in C#
Comments Off on C#. Interface as method Param
C#. Interfaces Is as
Is as
|
1 2 3 4 5 6 |
Shape[] shapes = { new Triangle("Triangle"), new Hexagon("Hexagon"), new Circle("Circle") }; for (int i = 0; i < shapes.Length; i++) { if (shapes[i] is IPointy) Console.WriteLine("Points in " + shapes[i].Name +" "+ (shapes[i] as IPointy).Points); else Console.WriteLine("Ipointy not supported in "+shapes[i].Name); } Console.ReadLine(); |
try catch – not best variant
|
1 2 3 4 5 6 7 |
Circle c1 = new Circle("Circle"); IPointy itf = null; try { itf = (IPointy)c1; } catch (InvalidCastException e) { Console.WriteLine(e.Message); } Console.ReadLine(); |
123
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Interace { class Program { static void Main(string[] args) { Triangle t = new Triangle("Triangle"); t.Draw(); Hexagon h = new Hexagon("Hexagon"); h.Draw(); Circle c = new Circle("Circle"); c.Draw(); // another example Shape[] shapes = { new Triangle("Triangle"), new Hexagon("Hexagon"), new Circle("Circle") }; for (int i = 0; i < shapes.Length; i++) { if (shapes[i] is IPointy) Console.WriteLine("Points in " + shapes[i].Name +" "+ (shapes[i] as IPointy).Points); else Console.WriteLine("Ipointy not supported in "+shapes[i].Name); } Console.ReadLine(); } // base class public class Shape { public string Name { get; set; } public Shape(string name) { Name = name; } public Shape() { } public virtual void Draw() { } } //declaring interface public interface IPointy { byte Points { get; } } // Triangle - derived from shape and implementing IPointy public class Triangle : Shape, IPointy { public Triangle() { } public Triangle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}",this.Name); } public byte Points { get { return 3; } } } // Hexagon - derived from shape and implementing IPointy public class Hexagon : Shape, IPointy { public Hexagon() { } public Hexagon(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 6; } } // << another implementation of IPointy } // // Circle - derived from shape and NOT implementing IPointy public class Circle : Shape { public Circle() { } public Circle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } } } } |
Posted in C#
Comments Off on C#. Interfaces Is as
C#. Interfaces – simple example
123 base class Shape Triangle, Hexagon, Circle – derived from Shape Triangle, Hexagon implement interface IPointy Circle – NOT implement IPointy
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Interace { class Program { static void Main(string[] args) { Triangle t = new Triangle("Triangle"); t.Draw(); Hexagon h = new Hexagon("Hexagon"); h.Draw(); Circle c = new Circle("Circle"); c.Draw(); Console.ReadLine(); } // base class public class Shape { public string Name { get; set; } public Shape(string name) { Name = name; } public Shape() { } public virtual void Draw() { } } //declaring interface public interface IPointy { byte Points { get; } } // Triangle - derived from shape and implementing IPointy public class Triangle : Shape, IPointy { public Triangle() { } public Triangle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}",this.Name); } public byte Points { get { return 3; } } } // Hexagon - derived from shape and implementing IPointy public class Hexagon : Shape, IPointy { public Hexagon() { } public Hexagon(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } public byte Points { get { return 6; } } // << another implementation of IPointy } // // Circle - derived from shape and NOT implementing IPointy public class Circle : Shape { public Circle() { } public Circle(string name) : base(name) { } public override void Draw() { Console.WriteLine("Shape name is {0}", this.Name); } } } } |
Posted in C#
Comments Off on C#. Interfaces – simple example
C#.System.GC
123
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SystemGC { class Program { static void Main(string[] args) { SomeClass sc = new SomeClass(); // some code GC.Collect(0, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); // some code Console.WriteLine( GC.GetGeneration(sc) + "\n\r" + GC.CollectionCount(0) + "\n\r" + GC.CollectionCount(0) + "\n\r" + GC.CollectionCount(0) ); } public class SomeClass { } } } |
Finalizer for unmanaged resources My Resource Wrapper
|
1 2 3 4 5 6 7 8 |
class MyResourceWrapper { ~MyResourceWrapper() { //free resources here Console.Beep(); } } |
IDisposable
|
1 2 3 4 5 6 7 8 9 10 11 |
class MyResourceWrapper2:IDisposable // << implement IDisposable here { public void Dispose() { // free resources here Console.Beep(); } } |
using Dispose in Main
|
1 2 3 |
MyResourceWrapper2 rw2 = new MyResourceWrapper2(); // do something if (rw2 is IDisposable) rw2.Dispose(); |
try finally Dispose
|
1 2 3 |
if (rw2 is IDisposable) rw2.Dispose(); try {/*do smth*/ } finally { if (rw2 is IDisposable) rw2.Dispose(); } |
using = try/finally
|
1 2 |
using (MyResourceWrapper2 rw2 = new MyResourceWrapper2()) { } |
combination of Finalization and Dispose()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class MyResourceWrapper3 : IDisposable { ~MyResourceWrapper3() { //free all unmanaged resources } public void Dispose() { //free all unmanaged resources //if called Dispose supress Finalization GC.SuppressFinalize(this); } } |
template from microsoft
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
class MyResourceWrapper4 : IDisposable { private bool disposed=false; public void Dispose() { CleanUp(true); GC.SuppressFinalize(this); } public void CleanUp(bool disposing) { if (!this.disposed) { if (disposing) {/*dispose all unmanaged resources*/ } } disposed = true; } ~MyResourceWrapper4() { /*dispose all unmanaged resources*/ CleanUp(false); } } |
Posted in C#
Comments Off on C#.System.GC
C#. Exceptions and Finally
123
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MultiExceptions { class Program { static void Main(string[] args) { try {/*do something*/} catch (ArgumentOutOfRangeException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } finally { // some code that will be 100% executed here } } } } |
Posted in C#
Comments Off on C#. Exceptions and Finally
C#. MultiExceptions
123 Consequence of exceptions – important! First concrete – last is general!
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MultiExceptions { class Program { static void Main(string[] args) { try {/*do something*/} catch (ArgumentOutOfRangeException e) { //#1 Console.WriteLine(e.Message); } catch (Exception e) //#2 { Console.WriteLine(e.Message); } } } } |
not Ok if
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MultiExceptions { class Program { static void Main(string[] args) { try {/*do something*/} catch (Exception e) { Console.WriteLine(e.Message); } catch (ArgumentOutOfRangeException e) { Console.WriteLine(e.Message); } } } } |
Posted in C#
Comments Off on C#. MultiExceptions