Posts

Showing posts from February, 2022

How to Convert String array to String in C#

 How to Convert String array to String in C#? Answer: Consider a string array string[] a= new string[]{"one", "two", "three" }; Above array can be converted to string using Join function string b = string.Join(", ", a);

Fatal refusing to merge unrelated histories git error

Fatal refusing to merge unrelated histories git error Consider you have two branches feature and master, you are trying to merge master branch changes into your feature branch, but both branch histories are different, hence git will not allow to merge directly Please use below command in the Git command prompt to merge branches with unrelated histories Command: git pull origin master --allow-unrelated-histories

How to serialize and deserialize a json using object (pre-defined class) in c#?

 How to serialize and deserialize a json using object (pre-defined class) in c#? Answer: Serialize class object into string: public class Employee { public int EmployeeId { get; set;} public string EmployeeName { get; set;} public string Designation { get; set;} } var employee = new Employee() { EmployeeId = 1, EmployeeName = "temp",  Designation = "Software Engineer" } Above class data can be serialized using below code snippet, please make sure Newtonsoft.Json is included in the namespace              string output = JsonConvert.SerializeObject(employee); Deserialize Json to class object: public class Employee { public int EmployeeId { get; set;} public string EmployeeName { get; set;} public string Designation { get; set;} } var data = "{\"EmployeeId\":1,\"EmployeeName\":\"temp\",\"Designation\":\"Software Engineer\"}" It can be deserialized using below code snippet, please make sure Newtonsoft.Json is i...
 How to convert String to String array in c#? Answer : consider below string with comma separated values string a = "a,b,c"; This can be convert to string array using default function called "Split" string[] b= a.Split(","); Now string has been converted to string array