git checkout -b YourBranchName
Tag: microsoft
Easy way to join strings on complex classes
Let’s say you have a class like that: public class Student { public string Name { get; set; } public string Surname { get; set; } public DateTime DateCreated { get; set; } … } If you want to join the name values of that class then you can use the code below: using System.Linq […]
How to get formatted JSON in C#
Like converting XML to Json or Json to XML, you can also use Newtonsoft to get formatted Json. private static string FormatJson(string json) { dynamic parsedJson = JsonConvert.DeserializeObject(json); return JsonConvert.SerializeObject(parsedJson, Formatting.Indented); } Note: You can use var instead of dynamic. Both will work.
How to solve extra blank page at end of Microsoft Reportviewer
To solve that problem you need to set the property ConsumeContainerWhitespace to True (in the properties dialog, F4).
Constructor for a static class in C#
C# has a static constructor for this purpose. static class YourClass { static YourClass() { // perform initialization here } } A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or […]
How to lock the ciritical code part in C#
According to Microsoft: The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released. The lock keyword calls Enter at the start of the block and Exit at the end of the block. lock keyword actually […]
Rename Report while exporting to PDF or Excel in Microsoft ReportViewer
ReportViewer1.LocalReport.DisplayName = “The_Name_For_My_Report”; or ReportViewer1.ServerReport.DisplayName = “The_Name_For_My_Report”;