воскресенье, 14 января 2018 г.

File: MVC UpLoad, then Write to DB in EntityFramework

https://www.mikesdotnetting.com/article/259/asp-net-mvc-5-with-ef-6-working-with-files

https://stackoverflow.com/questions/28194436/mvc4-image-upload-using-entity-framework-5-code-first

https://social.msdn.microsoft.com/Forums/en-US/1da1014b-a7d9-407d-8dc4-c914d158300d/cimage-store-and-read-from-database?forum=adodotnetentityframework

https://code.msdn.microsoft.com/How-to-save-Image-to-978a7b0b

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application

http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx

https://yogeshdotnet.com/file-upload-in-database-using-entity-framework-code-first-mvc/

https://cpratt.co/file-uploads-in-asp-net-mvc-with-view-models/

https://www.codeproject.com/Articles/658522/Storing-Images-in-SQL-Server-using-EF-and-ASP-NET

File To Bas64String Convert

BinaryWriter, BinaryReader

Writer

https://msdn.microsoft.com/ru-ru/library/system.io.binarywriter(v=vs.110).aspx

https://msdn.microsoft.com/ru-ru/library/system.io.binarywriter.write(v=vs.110).aspx

https://msdn.microsoft.com/ru-ru/library/yzxa6408(v=vs.110).aspx

https://metanit.com/sharp/tutorial/5.6.php

https://www.dotnetperls.com/binarywriter

https://stackoverflow.com/questions/4614318/whats-the-difference-between-a-streamwriter-and-a-binarywriter

http://csharp.net-informations.com/file/csharp-binarywriter.htm

https://professorweb.ru/my/csharp/thread_and_files/level3/3_11.php

Reader

https://msdn.microsoft.com/ru-ru/library/system.io.binaryreader(v=vs.110).aspx

https://metanit.com/sharp/tutorial/5.6.php

https://professorweb.ru/my/csharp/thread_and_files/level3/3_11.php

https://www.dotnetperls.com/binaryreader

https://ru.stackoverflow.com/questions/355195/binaryreader-%D0%9A%D0%B0%D0%BA-%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D0%B8%D1%82%D1%8C-%D0%BA%D0%BE%D0%BD%D0%B5%D1%86-%D1%84%D0%B0%D0%B9%D0%BB%D0%B0

http://csharp.net-informations.com/file/csharp-binaryreader.htm



Binary Serialization

https://docs.microsoft.com/en-us/dotnet/standard/serialization/binary-serialization

https://msdn.microsoft.com/ru-ru/library/system.runtime.serialization.formatters.binary.binaryformatter(v=vs.110).aspx

https://www.centerspace.net/examples/nmath/csharp/core/binary-serialization-example.php

https://msdn.microsoft.com/ru-ru/library/c5sbs8z9(v=vs.110).aspx

https://docs.microsoft.com/en-us/dotnet/standard/serialization/binary-serialization

https://metanit.com/sharp/tutorial/6.2.php

https://gist.github.com/vaclavbohac/962739

https://stackoverflow.com/questions/1749044/c-sharp-object-binary-serialization

http://www.ezzylearning.com/tutorial/binary-serialization-and-deserialization-in-csharp

https://johnlnelson.com/2014/07/01/binary-serialization-with-c-and-net/

https://www.codeproject.com/Articles/254617/Serialization-Part-I-Binary-Serialization


суббота, 13 января 2018 г.

Best way to reverse a string

https://stackoverflow.com/questions/228038/best-way-to-reverse-a-string


public static string ReverseXor(string s)
        {
            char[] charArray = s.ToCharArray();
            int len = s.Length - 1;

            for (int i = 0; i < len; i++, len--)
            {
                charArray[i] ^= charArray[len];
                charArray[len] ^= charArray[i];
                charArray[i] ^= charArray[len];
            }

            return new string(charArray);
        }

        public static string ReverseSB(string text)
        {
            StringBuilder builder = new StringBuilder(text.Length);
            for (int i = text.Length - 1; i >= 0; i--)
            {
                builder.Append(text[i]);
            }
            return builder.ToString();
        }

        public static string ReverseArray(string text)
        {
            char[] array = text.ToCharArray();
            Array.Reverse(array);
            return (new string(array));
        }

26251 Ticks String Builder (Length: 1) : called 10000 times.
33373 Ticks Array.Reverse (Length: 1) : called 10000 times.
20162 Ticks Xor (Length: 1) : called 10000 times.

51321 Ticks String Builder (Length: 10) : called 10000 times.
37105 Ticks Array.Reverse (Length: 10) : called 10000 times.
23974 Ticks Xor (Length: 10) : called 10000 times.

66570 Ticks String Builder (Length: 15) : called 10000 times.
26027 Ticks Array.Reverse (Length: 15) : called 10000 times.
24017 Ticks Xor (Length: 15) : called 10000 times.

101609 Ticks String Builder (Length: 25) : called 10000 times.
28472 Ticks Array.Reverse (Length: 25) : called 10000 times.
35355 Ticks Xor (Length: 25) : called 10000 times.

161601 Ticks String Builder (Length: 50) : called 10000 times.
35839 Ticks Array.Reverse (Length: 50) : called 10000 times.
51185 Ticks Xor (Length: 50) : called 10000 times.

230898 Ticks String Builder (Length: 75) : called 10000 times.
40628 Ticks Array.Reverse (Length: 75) : called 10000 times.
78906 Ticks Xor (Length: 75) : called 10000 times.

312017 Ticks String Builder (Length: 100) : called 10000 times.
52225 Ticks Array.Reverse (Length: 100) : called 10000 times.
110195 Ticks Xor (Length: 100) : called 10000 times.

2970691 Ticks String Builder (Length: 1000) : called 10000 times.
292094 Ticks Array.Reverse (Length: 1000) : called 10000 times.
846585 Ticks Xor (Length: 1000) : called 10000 times.

305564115 Ticks String Builder (Length: 100000) : called 10000 times.
74884495 Ticks Array.Reverse (Length: 100000) : called 10000 times.
125409674 Ticks Xor (Length: 100000) : called 10000 times.
It seems that Xor can be faster for short strings.