-
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#. Queue<>
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QueueGenerics { class Program { static void Main(string[] args) { //UseGenericStack(); UseQueue(); Console.ReadLine(); } static void UseQueue() { Queue<Person> queueOfPeople = new Queue<Person>(); queueOfPeople.Enqueue(new Person { Age = 123, FirstName = "123", LastName = "123" }); queueOfPeople.Enqueue(new Person { Age = 1234, FirstName = "1234", LastName = "1234" }); queueOfPeople.Enqueue(new Person { Age = 123, FirstName = "1234", LastName = "1234" }); //first in queue? Console.WriteLine("First is "+queueOfPeople.Peek().FirstName); // do some job with 1-st element in queue Person person = queueOfPeople.Peek(); Console.WriteLine("First is " + person.FirstName); queueOfPeople.Dequeue(); // getting out of queue //next in queue? Console.WriteLine("Next is " + queueOfPeople.Peek().FirstName); } public class Person { public int Age { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Person() { } public Person(int age, string firstName, string lastName) { Age = age; FirstName = firstName; LastName = lastName; } } } |
Posted in C#
Comments Off on C#. Queue<>
C#. Stack<>
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StackGenerics { class Program { static void Main(string[] args) { UseGenericStack(); Console.ReadLine(); } static void UseGenericStack() { Stack<Person> stackOfPeople = new Stack<Person>(); // filling stack stackOfPeople.Push(new Person { Age = 123, FirstName = "123", LastName = "123" }); stackOfPeople.Push(new Person { Age = 1234, FirstName = "1234", LastName = "1234" }); stackOfPeople.Push(new Person { Age = 12345, FirstName = "12345", LastName = "12345" }); Console.WriteLine("Count stack of people {0}", stackOfPeople.Count); //getting top element and pop it Person person = stackOfPeople.Peek(); //do something with person person.Age = 12; // for example stackOfPeople.Pop(); // get it away from the stack top //next person = stackOfPeople.Peek(); //do something with person person.Age = 12; // for example stackOfPeople.Pop(); // get it away from the stack top // next person = stackOfPeople.Peek(); //do something with person person.Age = 12; // for example stackOfPeople.Pop(); // get it away from the stack top Console.WriteLine("some job done"); Console.WriteLine("Count stack of people {0}", stackOfPeople.Count); } } public class Person { public int Age { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Person() { } public Person(int age, string firstName, string lastName) { Age = age; FirstName = firstName; LastName = lastName; } } } |
Posted in C#
Comments Off on C#. Stack<>
C#.List<>
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 |
using System; using System.Collections; using System.Collections.Generic; // << add using System.Linq; using System.Text; using System.Threading.Tasks; namespace ListGenerics1 { class Program { static void Main(string[] args) { UseGenericsList(); Console.ReadLine(); } public static void UseGenericsList() { List <Person> people = new List<Person>() { new Person { Age = 123, FirstName="123", LastName="123" } }; // Count Console.WriteLine("Items in list: {0}",people.Count); //Enumerate foreach (Person p in people) { Console.WriteLine(p); } // Foreach... people.Add(new Person { Age = 123, FirstName = "123", LastName = "123" }); // Person[] arrayOfPeople = people.ToArray(); for (int i = 0; i < arrayOfPeople.Length; i++) { Console.WriteLine("First Names: {0}", arrayOfPeople[i].FirstName); } } } public class Person { public int Age{get;set;} public string FirstName { get; set; } public string LastName { get; set; } public Person() { } public Person(int age, string firstName, string lastName) { Age = age; FirstName = firstName; LastName = lastName; } } } |
Posted in C#
Comments Off on C#.List<>
C#. IComparer as property
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 |
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IComparerExample { class Program { static void Main(string[] args) { Car[] Cars = { new Car("A",123,1), new Car("123",123,3), new Car("C",123,7), new Car("123",123,4), new Car("123",123,2) }; Console.WriteLine("Not Sorted"); foreach (var car in Cars) { Console.WriteLine(car.Name); } // << not sorted //Array.Sort(Cars, new NameComparer()); Array.Sort(Cars,Car.SortByName); Console.WriteLine("Sorted"); foreach (var car in Cars) { Console.WriteLine(car.Name); } // << sorted Console.ReadLine(); } } public class Car { public int ID { get; set; } public int Speed { get; set; } public string Name { get; set; } public static IComparer SortByName { get { return (IComparer)new NameComparer(); } // <<< IComparer in property } public Car(string name, int speed, int id) { Name = name; Speed = speed; ID = id; } } public class NameComparer : IComparer { public int Compare(object x, object y) { Car c1 = x as Car; Car c2 = y as Car; if (c1 != null && c2 != null) { return string.Compare(c1.Name, c2.Name); } else throw new ArgumentException("Param is not Car"); //throw new NotImplementedException(); } } } |
Posted in C#
Comments Off on C#. IComparer as property
C#. IComparer
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 |
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IComparerExample { class Program { static void Main(string[] args) { Car[] Cars = { new Car("A",123,1), new Car("123",123,3), new Car("C",123,7), new Car("123",123,4), new Car("123",123,2) }; Console.WriteLine("Not Sorted"); foreach (var car in Cars) { Console.WriteLine(car.Name); } // << not sorted Array.Sort(Cars, new NameComparer()); Console.WriteLine("Sorted"); foreach (var car in Cars) { Console.WriteLine(car.Name); } // << sorted Console.ReadLine(); } } public class Car { public int ID { get; set; } public int Speed { get; set; } public string Name { get; set; } public Car(string name, int speed, int id) { Name = name; Speed = speed; ID = id; } } public class NameComparer : IComparer { public int Compare(object x, object y) { Car c1 = x as Car; Car c2 = y as Car; if (c1 != null && c2 != null) { return string.Compare(c1.Name, c2.Name); } else throw new ArgumentException("Param is not Car"); //throw new NotImplementedException(); } } } |
Posted in C#
Comments Off on C#. IComparer
C#. IClonable – creating complicated Clone
Main idea – is correctly fill method Clone() 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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IClonable2 { class Program { static void Main(string[] args) { } } public class PointDescription { public string Name { get; set; } public Guid ID { get; set; } public PointDescription() { Name = "No-name"; ID = Guid.NewGuid(); } } public class Point2 : ICloneable { public int X { get; set; } public int Y { get; set; } public Point2(int x, int y) { X = x; Y = y; } public Point2() { } public override string ToString() { //return base.ToString(); return string.Format("X={0},Y={1}", X, Y); } public object Clone() { return new Point(this.X, this.Y); // throw new NotImplementedException(); } } public class Point : ICloneable { public int X { get; set; } public int Y { get; set; } public PointDescription desc = new PointDescription(); public Point(int x, int y, string name) { X = x; Y = y; desc.Name = name; } public Point(int x, int y) { X = x; Y = y; } public Point() { } public override string ToString() { return string.Format("X={0},Y={1};Name={2};\nID={3}", X, Y, desc.Name, desc.ID); } public object Clone() { //return this.MemberwiseClone(); // << shallow copy, bad for this case !!! Point newPoint = (Point)this.MemberwiseClone(); // filling data PointDescription currentDesc = new PointDescription(); currentDesc.Name = this.desc.Name; newPoint.desc = currentDesc; return newPoint; // now OK!!! } } } |
Posted in C#
Comments Off on C#. IClonable – creating complicated Clone
C#. IClonable
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClonablePoint { class Program { static void Main(string[] args) { Point p1 = new Point(); Point p2 = (Point)p1.Clone(); // <<< clone of p1 in the heap!!! } } public class Point:ICloneable { public int X { get; set; } public int Y { get; set; } public Point(int x, int y) { X = x;Y = y; } public Point() { } public override string ToString() { //return base.ToString(); return string.Format("X={0},Y={1}", X, Y); } public object Clone() { // return new Point(this.X, this.Y); return this.MemberwiseClone(); // if doesn't exist refs to other objs // throw new NotImplementedException(); } } } |
Posted in C#
Comments Off on C#. IClonable
C#. Iteration with Yield
to support foreach in GarageClass 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 |
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IEnumerable123 { class Program { static void Main(string[] args) { Garage carLot = new Garage(); foreach (Car c in carLot) { Console.WriteLine(c.Name); } // Garage should support IEnumerator Console.ReadLine(); } } public class Garage { private Car[] carArray = new Car[4]; public Garage() { carArray[0] = new Car("name1"); carArray[1] = new Car("name2"); carArray[2] = new Car("name3"); carArray[3] = new Car("name4"); } public IEnumerator GetEnumerator() { foreach (Car c in carArray) { yield return c; } } } public class Car { public string Name{get; set;} public Car(string aname){ Name = aname; } } } |
Posted in C#
Comments Off on C#. Iteration with Yield
C#. IEnumerable и Ienumerator
To support foreach in some classes – see example below Ok
|
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 |
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IEnumerable123 { class Program { static void Main(string[] args) { Garage carLot = new Garage(); foreach (Car c in carLot) { Console.WriteLine(c.Name); } // <<< Here !!! Console.ReadLine(); } } public class Garage: IEnumerable { private Car[] carArray = new Car[4]; public Garage() { carArray[0] = new Car("name1"); carArray[1] = new Car("name2"); carArray[2] = new Car("name3"); carArray[3] = new Car("name4"); } public IEnumerator GetEnumerator() { return carArray.GetEnumerator(); } } public class Car { public string Name{get; set;} public Car(string aname){ Name = aname; } } } |
Not Ok
|
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 |
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IEnumerable123 { class Program { static void Main(string[] args) { Garage carLot = new Garage(); foreach (Car c in carLot) { Console.WriteLine(c.Name); } // Garage should support IEnumerator Console.ReadLine(); } } public class Garage { private Car[] carArray = new Car[4]; public Garage() { carArray[0] = new Car("name1"); carArray[1] = new Car("name2"); carArray[2] = new Car("name3"); carArray[3] = new Car("name4"); } } public class Car { public string Name{get; set;} public Car(string aname){ Name = aname; } } } |
Posted in C#
Comments Off on C#. IEnumerable и Ienumerator
C#. Multi inheritance of interfaces
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InterfacesMultiInheritance { class Program { static void Main(string[] args) { } } public interface IDrawable { void Draw(); } public interface IPrintable { void Draw(); void Print(); } // possible names conflict public interface IShape : IDrawable, IPrintable { int GetNumberOfSides(); } class Rectangle : IShape // not explicit { public void Draw() { // throw new NotImplementedException(); } public int GetNumberOfSides() { return 4; // throw new NotImplementedException(); } public void Print() { // throw new NotImplementedException(); } } class Rectangle2 : IShape // not explicit { void IPrintable.Draw() { // throw new NotImplementedException(); } void IDrawable.Draw() { // throw new NotImplementedException(); } int IShape.GetNumberOfSides() { return 4; //throw new NotImplementedException(); } void IPrintable.Print() { //throw new NotImplementedException(); } } } |
Posted in C#
Comments Off on C#. Multi inheritance of interfaces