-
MY PROJECTS
-
Recent Posts
- SpringBoot. Exception Management
- Java.Hibernate.JoinTableAnnotation
- SpringBoot.Making our first starter and autoconfiguration
- Spring. Creating main annotation to start business logic
- Spring.Reading from properties file
- Spring.How to define spring version inside springBoot ?
- SpringBoot App inside Docker
- Kafka.FirstExperience
- Docker.MySql and Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
- Gradle.Tips
- Spring.AppConfig
- Leetcode.Best-time-to-buy-and-sell-stock
- LeetCode.ClimbStairs.Fibbonacci
- Leetcode.Roman-to-integer
- LeetCode.Palindrome-number
- Java.DesignPatterns.Lightweight
- Java.DesignPatterns.Proxy
- Java.DesignPatterns.Facade
- Java.DesignPatterns.Composite
- Java.DesignPatterns.Bridge
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)
- Регулярные выражения
- Тестирование приложений
Author Archives: Stanislav_Panteleev
C#. Custom generic methods
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CustomGenerics { class Program { static void Main(string[] args) { int a = 1; int b = 2; Swap<int>(ref a,ref b); Console.WriteLine(a+""+b); string s1 = "1"; string s2 = "2"; Swap<string>(ref s1, ref s2); Console.WriteLine(s1 + "" + s2); Console.ReadLine(); } static void Swap<T>(ref T a, ref T b) { T temp; temp = a; a = b; b = temp; } } } |
Posted in C#
Comments Off on C#. Custom generic methods
C#. SortedSet<>
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SortedSetGenerics { class Program { static void Main(string[] args) { UseSortedSet(); Console.ReadLine(); } static void UseSortedSet() { SortedSet<Person> peopleSortedSet = new SortedSet<Person>(new SortpeopleByAge()) { new Person { Age = 123, FirstName = "123", LastName = "123" }, new Person { Age = 1234, FirstName = "1234", LastName = "1234" }, new Person { Age = 12345, FirstName = "12345", LastName = "12345" }, }; foreach (Person p in peopleSortedSet) { Console.WriteLine(p); // elements sorted by age } } 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(); } } class SortpeopleByAge : IComparer<Person> { public int Compare(Person x, Person y) { if (x.Age > y.Age) { return 1; } if (x.Age > y.Age) { return -1; } else return 0; //throw new NotImplementedException(); } } } } |
Posted in C#
Comments Off on C#. SortedSet<>
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#. IComparable
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IComparableExample { class Program { static void Main(string[] args) { Car[] Cars = { new Car("123",123,1), new Car("123",123,3), new Car("123",123,7), new Car("123",123,4), new Car("123",123,2) }; Console.WriteLine("Not Sorted"); foreach (var car in Cars) { Console.WriteLine(car.ID); } // << not sorted Array.Sort(Cars); Console.WriteLine("Sorted"); foreach (var car in Cars) { Console.WriteLine(car.ID); } // << sorted Console.ReadLine(); } } public class Car:IComparable { 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 int CompareTo(object obj) { Car temp = obj as Car; if (temp != null) { if (this.ID > temp.ID) return 1; if (this.ID < temp.ID) return -1; else return 0; } else throw new ArgumentException("Param is not Car"); } } } |
Posted in Без рубрики
Comments Off on C#. IComparable
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