This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FileSysInfo | |
| { | |
| static void Main() | |
| { | |
| // You can also use System.Environment.GetLogicalDrives to | |
| // obtain names of all logical drives on the computer. | |
| System.IO.DriveInfo di = new System.IO.DriveInfo(@"C:\"); | |
| Console.WriteLine(di.TotalFreeSpace); | |
| Console.WriteLine(di.VolumeLabel); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| If you're used to function pointers in C, a delegate is basically a pair of pointers rolled into one: | |
| A pointer to an object (optional) | |
| A pointer to a method of that object | |
| That means a single delegate passes all the information needed to locate a function in your program, whether it's a static method or associated with an object. | |
| You define them like this in C#: | |
| public delegate void FooCallbackType( int a, int b, int c ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /.*?\n | |
| Regex for removing xml comments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // With identity conversions you may have generic variance in mind, however, this is not possible due to | |
| // Identity conversions are mostly important for tuples when it comes to constructed types. If you could easily convert from (int, int) to (int x, int y) but not from IEnumerable<(int, int)> to IEnumerable(<int x, int y>) you would be quite annoyed. | |
| //Although you can ignore some preceding information and ignore what the CLR does with tuples, you'll be able to do more with tuples and better understand the behavior. | |
| //Unlike anonymous types, in which unique sequence of property names within an assembly causes the compiler to generate a new type, typles don't require any extra types to be generated by the compiler. Instead, it uses a new set of types from the framework. | |
| //Tuples in C# 7are implemented using the System.ValueTuple. A description of any type of is very much like the description of tuple types from earlier: it's a value type with public fields. You might expect the ValueTuple to be static - i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Dynamic typing supports custom behavior via IDynamicMetaObjectProvider and the DynamicObject class | |
| Dynamic typing is implemented with both compiler and framework features. The framework optimizes and caches for efficiency. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Application app = new Application { Visible = true }; | |
| Document doc = app.Documents.Add*(; | |
| Paragraph para = doc.Paragraphs.Add(); | |
| para.Range.Text = "Simple new code"; | |
| doc.SaveAs2<-->(FileName: "demo2.docx"); | |
| doc.Close(); | |
| app.Application.Quit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void M(int x, int y) { } | |
| void M<T>(T y, int x) { } | |
| void M2() | |
| { | |
| M(3, 4); | |
| M(y: 3, x: 4); // Invokes M(int, int) | |
| M(y: 3, 4); // Invokes M<T>(T, int) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Example : IDisposable | |
| { | |
| private IntPtr buffer; // неуправляемый буфер памяти | |
| private SafeHandle resource; // управляемый ресурс | |
| public Example() // конструктор | |
| { | |
| this.buffer = ... | |
| this.resource = ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void Main() | |
| { | |
| var store = new NumberStore(); | |
| WriteLine($"Исходная последовательность: {store.ToString()}"); | |
| ref var value = ref store.FindNumber(16); | |
| value *= 2; | |
| WriteLine($"Новая последовательность: {store.ToString()}"); | |
| //: 1 3 7 15 31 63 127 255 511 1023 | |
| //: 1 3 7 15 62 63 127 255 511 1023 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| &array[0] | |
| [DllImport("kernel32", SetLastError = true)] | |
| static extern unsafe IntPtr CreateFile( | |
| string FileName, | |
| uint DesiredAccess, | |
| uint ShareMode, | |
| uint SecurityAttributes, | |
| uint CreationDisposition, |