Conversion double array to byte array

Assuming you want the doubles placed in the corresponding byte array one after the other, LINQ can make short work out of this: static byte[] GetBytes(double[] values) { return values.SelectMany(value => BitConverter.GetBytes(value)).ToArray(); } Alternatively, you could use Buffer.BlockCopy(): static byte[] GetBytesAlt(double[] values) { var result = new byte[values.Length * sizeof(double)]; Buffer.BlockCopy(values, 0, result, 0, result.Length); … Read more

C# Xml Serialization & Deserialization

In your deserialization code you’re creating a MemoryStream and XmlTextWriter but you’re not giving it the string to deserialize. using (MemoryStream memStream = new MemoryStream()) { using (XmlTextWriter textWriter = new XmlTextWriter(memStream, Encoding.Unicode)) { // Omitted } } You can pass the bytes to the memory stream and do away with the XmlTextWriter altogether. using … Read more

Generic List as parameter on method

To take a generic List<T> vs a bound List<int> you need to make the method generic as well. This is done by adding a generic parameter to the method much in the way you add it to a type. Try the following void Export<T>(List<T> data, params string[] parameters) { … }

how to put checkboxes in datagrid in windows mobile 6 using c#?

Here’s some code from and old blog by Eric Hartwell (pulled into SO using the wayback machine): private void SetupTableStyles() { Color alternatingColor = SystemColors.ControlDark; DataTable vehicle = dataSource.Tables[1]; // ID Column DataGridCustomTextBoxColumn dataGridCustomColumn0 = new DataGridCustomTextBoxColumn(); dataGridCustomColumn0.Owner = this.dataGrid1; dataGridCustomColumn0.Format = “0##”; dataGridCustomColumn0.FormatInfo = null; dataGridCustomColumn0.HeaderText = vehicle.Columns[0].ColumnName; dataGridCustomColumn0.MappingName = vehicle.Columns[0].ColumnName; dataGridCustomColumn0.Width = dataGrid1.Width … Read more

How to iterate through Dictionary and change values?

According to MSDN: The foreach statement is a wrapper around the enumerator, which allows only reading from the collection, not writing to it. Use this: var dictionary = new Dictionary<string, double>(); // TODO Populate your dictionary here var keys = new List<string>(dictionary.Keys); foreach (string key in keys) { dictionary[key] = Math.Round(dictionary[key], 3); }

List readonly with a private set

I think you are mixing concepts. public List<string> myList {get; private set;} is already “read-only”. That is, outside this class, nothing can set myList to a different instance of List<string> However, if you want a readonly list as in “I don’t want people to be able to modify the list contents“, then you need to … Read more