-
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#. Linq and Arrays. Simple Examples
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 87 88 89 90 91 92 93 94 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace linqSimpleArray { class Program { static void Main(string[] args) { QueryOverStrings(); Console.ReadLine(); } static void QueryOverStrings() { string[] games = { "Morrowwind", "Uncharted 2", "Fallout 3", "Daxter", "System Shock 2" }; // get games only with spaces inside IEnumerable<string> subset = from g in games where g.Contains(" ") orderby g select g; // the same through implicit tipization var subset2 = from g in games where g.Contains(" ") orderby g select g; // linq operator will be implemented here foreach (string s in subset) Console.WriteLine("Item: {0}", s); Console.WriteLine("123"); foreach (string s in subset2) Console.WriteLine("Item: {0}", s); //------------- immediate execution of linq int[] numbers = { 10,20,30,40,1,2,3 }; int[] subarray = (from i in numbers where i<10 select i).ToArray<int>(); // executed here foreach (int j in subarray) Console.WriteLine("Item: {0}", j); // or //for (int j = 0; j < subarray.Length; j++) { Console.WriteLine("Item: {0}", subarray[j]); } LinqReturnExamples.GetStringSubset(); LinqReturnExamples.GetStringSubsetAsArray(); } } class LinqReturnExamples { public static IEnumerable<string> GetStringSubset() { string[] games = { "Morrowwind", "Uncharted 2", "Fallout 3", "Daxter", "System Shock 2" }; // get games only with spaces inside IEnumerable<string> subset = from g in games where g.Contains(" ") orderby g select g; return subset; } public static string[] GetStringSubsetAsArray() { string[] games = { "Morrowwind", "Uncharted 2", "Fallout 3", "Daxter", "System Shock 2" }; // get games only with spaces inside string[] subarray = (from g in games where g.Length < 10 select g).ToArray<string>(); // executed here return subarray; } } } |
Posted in C#
Comments Off on C#. Linq and Arrays. Simple Examples
C#. ANONYMOUS TYPES. IMPLICIT CLASS OBJECTS CREATION And Unsafe Code
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AnonymousTypes { class Program { static void Main(string[] args) { // implicitly creating class, only for LINQ // in normal situation create classes normally var myCar = new { Color = "Bright", Make = "Saab", Speed = 55 }; Console.WriteLine("My car is a {0} {1}",myCar.Color,myCar.Make); ReflectAnonymousType(myCar); PrintValueAndAdresses(); Console.ReadLine(); } static void ReflectAnonymousType(object obj) { Console.WriteLine("obj is an instance of {0}:",obj.GetType().Name); // continued in Troelsen, p. 452 } unsafe static void PrintValueAndAdresses() { int i; int* ptrToMyInt = &i; *ptrToMyInt = 123; Console.WriteLine("Value of i {0}",i); Console.WriteLine("Adress of ptrToMyInt {0}", (int)&ptrToMyInt); } } } |
Posted in C#
Comments Off on C#. ANONYMOUS TYPES. IMPLICIT CLASS OBJECTS CREATION And Unsafe Code
C#. LinqExample
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 LINQExamples { class Program { static void Main(string[] args) { QueryOverStrings(); } static void QueryOverStrings() { string[] strings = { "123", "123 4", "1234 5" }; //linq implementation IEnumerable<string> subset = from s in strings where s.Contains(" ") orderby s select s; foreach (string s in subset) Console.WriteLine("Item {0}",s); Console.ReadLine(); } } } |
Posted in C#
Comments Off on C#. LinqExample
C#. Anonymous types. Implicit class objects creation
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AnonymousTypes { class Program { static void Main(string[] args) { // implicitly creating class, only for LINQ // in normal situation create classes normally var myCar = new { Color = "Bright", Make = "Saab", Speed = 55 }; Console.WriteLine("My car is a {0} {1}",myCar.Color,myCar.Make); ReflectAnonymousType(myCar); PrintValueAndAdresses(); Console.ReadLine(); } static void ReflectAnonymousType(object obj) { Console.WriteLine("obj is an instance of {0}:",obj.GetType().Name); // continued in Troelsen, p. 452 } unsafe static void PrintValueAndAdresses() { int i; int* ptrToMyInt = &i; *ptrToMyInt = 123; Console.WriteLine("Value of i {0}",i); Console.WriteLine("Adress of ptrToMyInt {0}", (int)&ptrToMyInt); } } } |
Posted in C#
Comments Off on C#. Anonymous types. Implicit class objects creation
C#. UserTypeCast
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 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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace UserConverts { class Program { static void Main(string[] args) { int a = 123; long b = a; // not explicit int c=(int)b;// explicit convert, I say to compiler "I know ehat am I doing" Base someBase; someBase = new Derived(); // not explicit Derived someDerived = (Derived)(someBase); // explicit Rectangle r = new Rectangle(15,4); Console.WriteLine(r.ToString()); r.Draw(); Console.WriteLine(); //converting Rectangle to square using explicit Square s = (Square)r; Console.WriteLine(r.ToString()); s.Draw(); Console.WriteLine(""); //converting Square to Rectangle using implicit Rectangle r2 = (Rectangle)s; Console.WriteLine(r2); r2.Draw(); Console.ReadLine(); } class Base { } class Derived : Base { } } public class Rectangle { public int Width { get; set; } public int Height { get; set; } public Rectangle(int w, int h) { Width = w; Height = h; } public Rectangle() { } public void Draw() { for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { Console.Write("*"); } Console.WriteLine(); } } public override string ToString() { return string.Format("Width {0} Height {1} ",Width,Height); } public static implicit operator Rectangle(Square s) { Rectangle r = new Rectangle(); r.Height = s.Length; r.Width = 2 * s.Length; return r; } } public class Square { public int Length { get; set; } public Square(int l) { Length = l; } public Square() { } public void Draw() { for (int i = 0; i < Length; i++) { for (int j = 0; j < Length; j++) { Console.Write("*"); } Console.WriteLine(); } } // EXPLICIT RECTANGLE TO SQUARE public static explicit operator Square(Rectangle r) { Square s = new Square(); s.Length = r.Height; return s; } } } |
Posted in C#
Comments Off on C#. UserTypeCast
C#. StringIndexators
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 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 |
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StringIndexators { class Program { static void Main(string[] args) { // PeopleCollection behave like array !!! PeopleCollection2 people2 = new PeopleCollection2(); people2["123"] = new Person(123, "123", "123"); people2["1234"] = new Person(123, "1234", "123"); people2["12345"] = new Person(123, "12345", "123"); people2["123456"] = new Person(123, "123456", "123"); Person somePerson = people2["123"]; Console.WriteLine(somePerson.FirstName); Console.ReadLine(); } } 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; } public override string ToString() { return ("Age=" + Age); // return base.ToString(); } } public class PeopleCollection : IEnumerable { private ArrayList ArrayListPeople = new ArrayList(); public Person GetPerson(int pos) { return (Person)ArrayListPeople[pos]; } public void AddPerson(Person p) { ArrayListPeople.Add(p); } public void ClearPeople() { ArrayListPeople.Clear(); } // foreach support public IEnumerator GetEnumerator() { return ArrayListPeople.GetEnumerator(); } public int Count { get { return ArrayListPeople.Count; } } // adding indexator - then collection will have behaviour like array public Person this[int index] { get { return (Person)ArrayListPeople[index]; } set { ArrayListPeople.Insert(index, value); } } } public class PeopleCollection2 : IEnumerable { private Dictionary<string, Person> dictPeople = new Dictionary<string, Person>(); // adding indexator - then collection will have behaviour like array public Person this[string name] { get { return (Person)dictPeople[name]; } set { dictPeople[name] = value; } } public void ClearPeople() { dictPeople.Clear(); } public int Count { get { return dictPeople.Count; } } // foreach support public IEnumerator GetEnumerator() { return dictPeople.GetEnumerator(); } } } |
Posted in C#
Comments Off on C#. StringIndexators
C#. Indexators Custom collection behave like array
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 87 88 89 90 |
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Indexators { class Program { static void Main(string[] args) { // PeopleCollection behave like array !!! PeopleCollection people = new PeopleCollection(); people[0] = new Person(123, "123", "123"); people[1] = new Person(123, "123", "123"); people[2] = new Person(123, "123", "123"); people[3] = new Person(123, "123", "123"); for (int i = 0; i < people.Count; i++) { Console.WriteLine(people[i].FirstName); } Console.ReadLine(); } } 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; } public override string ToString() { return ("Age=" + Age); // return base.ToString(); } } public class PeopleCollection : IEnumerable { private ArrayList ArrayListPeople = new ArrayList(); public Person GetPerson(int pos) { return (Person)ArrayListPeople[pos]; } public void AddPerson(Person p) { ArrayListPeople.Add(p); } public void ClearPeople() { ArrayListPeople.Clear(); } // foreach support public IEnumerator GetEnumerator() { return ArrayListPeople.GetEnumerator(); } public int Count { get { return ArrayListPeople.Count; } } // adding indexator - then collection will have behaviour like array public Person this[int index] { get { return (Person)ArrayListPeople[index]; } set { ArrayListPeople.Insert(index, value); } } } } |
Posted in C#
Comments Off on C#. Indexators Custom collection behave like array
C#. Delegates.AnonymousMethods and LambdaExpression
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AnonymMethods { class Program { static void Main(string[] args) { int localInt = 123; SomeClass sc = new SomeClass(); sc.SetDelegate(SomeHandler); SomeClass.SomeDelegate d = new SomeClass.SomeDelegate(SomeEventHandler); sc.SomeEvent1 += d; // assigning anonymous methods with or without params sc.SomeEvent1 += delegate { Console.WriteLine("Anonymous method "); }; // << works without param - why? sc.SomeEvent1 += delegate(string msg) { Console.WriteLine("Anonymous method "+msg); }; sc.SomeEvent1 += delegate { Console.WriteLine("Anonymous method with local var "+localInt); }; // << works without param - why? // lambda expression - like alias for above examples sc.SomeEvent1 += (string msg) => { Console.WriteLine("Lambda expression " + msg); }; // start testing... sc.SomeDelegateMethod(); sc.SomeEventMethod(); Console.ReadLine(); } public static void SomeHandler(string Aparam) { Console.WriteLine(Aparam); } public static void SomeEventHandler(string Aparam) { Console.WriteLine(Aparam); } } class SomeClass { // delegate public delegate void SomeDelegate(string Aparam); private SomeDelegate listOfHandlers; public void SetDelegate(SomeDelegate method) { listOfHandlers += method; } //event public event SomeDelegate SomeEvent1; // firing methods public void SomeDelegateMethod() { if (listOfHandlers != null) { listOfHandlers("someDelegateMessage"); } } public void SomeEventMethod() { if (SomeEvent1 != null) { SomeEvent1("someEventMessage"); } } } } |
Posted in C#
Comments Off on C#. Delegates.AnonymousMethods and LambdaExpression
C#. GenericEventHandler
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Events2 { class Program { static void Main(string[] args) { Car c = new Car(); Car.SomeDelegate d = new Car.SomeDelegate(SomeEvent1Handler); c.SomeEvent1 += d; // added EventHandler c.SomeEvent1 -= d; // removed EventHandler EventHandler<CarEventArgs> d2 = new EventHandler<CarEventArgs>(SomeEvent2Handler); c.SomeEvent2 += d2; c.SomeMethod(); Console.ReadLine(); } public static void SomeEvent1Handler(string msg) { Console.WriteLine("SomeEvent1Handler " + msg); } public static void SomeEvent2Handler(object sender, CarEventArgs e) { if (sender is Car) { Car c = (Car)sender; Console.WriteLine("{0} says {1} ", sender, e.msg); } } } public class Car { public delegate void SomeDelegate(string msg); public delegate void SomeDelegate2(object sender, CarEventArgs e); public event SomeDelegate SomeEvent1; //public event SomeDelegate2 SomeEvent2; public event EventHandler<CarEventArgs> SomeEvent2; public void SomeMethod() { //some code if (SomeEvent1 != null) SomeEvent1("someMessage"); // fire Event Handler //some code if (SomeEvent2 != null) SomeEvent2(this, new CarEventArgs("someMessage2")); // fire Event Handler } } public class CarEventArgs : EventArgs { public readonly string msg; public CarEventArgs(string message) { msg = message; } } } |
Posted in C#
Comments Off on C#. GenericEventHandler
C#. Event with special Args
define class
|
1 2 3 4 |
public class CarEventArgs : EventArgs { public readonly string msg; public CarEventArgs(string message) { msg = message;} } |
and use it in code… 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.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Events2 { class Program { static void Main(string[] args) { Car c = new Car(); Car.SomeDelegate d = new Car.SomeDelegate(SomeEvent1Handler); c.SomeEvent1 += d; // added EventHandler c.SomeEvent1 -= d; // removed EventHandler Car.SomeDelegate2 d2 = new Car.SomeDelegate2(SomeEvent2Handler); c.SomeEvent2 += d2; // added EventHandler // c.SomeEvent2 -= d2; // removed EventHandler //c.SomeEvent1 += new Car.SomeDelegate(SomeEvent1Handler); // another way to assign Event handler //c.SomeEvent2 += new Car.SomeDelegate2(SomeEvent2Handler); c.SomeMethod(); Console.ReadLine(); } public static void SomeEvent1Handler(string msg) { Console.WriteLine("SomeEvent1Handler " + msg); } public static void SomeEvent2Handler(object sender, CarEventArgs e) { if (sender is Car) { Car c = (Car)sender; Console.WriteLine("{0} says {1} ",sender, e.msg); } } } public class Car { public delegate void SomeDelegate(string msg); public delegate void SomeDelegate2(object sender, CarEventArgs e); public event SomeDelegate SomeEvent1; public event SomeDelegate2 SomeEvent2; public void SomeMethod() { //some code if (SomeEvent1 != null) SomeEvent1("someMessage"); // fire Event Handler //some code if (SomeEvent2 != null) SomeEvent2(this, new CarEventArgs("someMessage2")); // fire Event Handler } } public class CarEventArgs : EventArgs { public readonly string msg; public CarEventArgs(string message) { msg = message;} } } |
Posted in C#
Comments Off on C#. Event with special Args