Puzzling looking at the title!!!!
Lets look at this code
var a =(0.1 + 0.2) - 0.3; Console.WriteLine("a = "+ a);
I am sure you are expecting "0" but its not.
It is 5.55111512312578E-17
check my fiddle here Open my Fiddle
var a =(0.1 + 0.2) - 0.3; Console.WriteLine("a = "+ a);
using System; using System.Globalization; public class Program { public static void Main() //suman first convert to byte[] byte[] bb = ConvertHexadecimalStringToByteArray("030100AA1902"); //calculate checksum with the above byte[] Console.WriteLine(calculateCheckSum(bb)); } //Following converts the hex to a byte[] public static byte[] ConvertHexadecimalStringToByteArray(string hexadecimalString) { if (hexadecimalString.Length % 2 != 0) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "HexaDecimal cannot have an odd number of digits: {0}", hexadecimalString)); } byte[] hexByteArray = new byte[hexadecimalString.Length / 2]; for (int index = 0; index < hexByteArray.Length; index++) { string byteValue = hexadecimalString.Substring(index * 2, 2); hexByteArray[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture); } return hexByteArray; } //calculates the checksum from the byte[] private static byte calculateCheckSum(byte[] byteData) { Byte chkSumByte = 0x00; for (int i = 0; i < byteData.Length; i++) chkSumByte ^= byteData[i]; return chkSumByte; } }
string xmlString ="somexml string"; /// this will actually contain the xml... DataTable dt = new DataTable(); System.IO.StringReader oreader=new System.IO.StringReader (xmlString); dt.ReadXml(oreader);
string xmlString ="somexml string"; /// this will actually contain the xml... DataSet ds = new DataSet(); System.IO.StringReader oreader=new System.IO.StringReader (xmlString); ds.ReadXml(oreader); DataTable dtt=ds.tables[0];
string xmlString ="somexml string"; /// this will actually contain the xml... DataTable dt = new DataTable(); System.IO.StringReader oreader=new System.IO.StringReader (xmlString); dt.ReadXmlSchema("xmlSchema.xsd"); -- If schema is in a xsd dt.ReadXmlSchema(oreader); // if the XML string has the XML Schema. dt.ReadXml(oreader);
dt.WriteXml("a.xml",XmlWriteMode.WriteSchema);If you are not generating the XML, you can still generate schema from different XML editors. Like for EX if you have visual Studio you can use the create Schema to create the XML and then load it or the easier way of using the Dataset :)
FirstName | LastName | EmailAddress |
bob | j | Bob.email@email1.com |
santa | Banta |
<root> <table> <firstname>bob</firstname> <lastname>j</lastname> <emailaddress>Bob.email@email1.com</emailaddress> </table> <table> <firstname>santa</firstname> <lastname>Banta</lastname> </table> </root>
public DataTable writeEmptyStringToNullElelments(DataTable dt){ foreach (DataRow oRow in dt.Rows) { for (int colCount = 0; colCount < oRow.ItemArray.Length; colCount++) { if (oRow.ItemArray[colCount] == DBNull.Value) { oRow.SetField(colCount, string.Empty); } } } dt.AcceptChanges(); return dt; }
<root> <table> <firstname>bob</firstname> <lastname>j</lastname> <emailaddress>Bob.email@email1.com</emailaddress> </table> <table> <firstname>santa</firstname> <lastname>Banta</lastname> <emailaddress /> </table> </root>
<Table> <ID>1</ID> <FirstName>Bob</FirstName> </LastName>Burger</LastName> </Table>
<StudentInfo> <ID>1</ID> <FirstName>Bob</FirstName> </LastName>Burger</LastName> </StudentInfo>
dt.WriteXml(writer, XmlWriteMode.WriteSchema, true);.. what this does is adds the schema at the top.
public static Dictionary splitStringToaDictionary(string stringToConvertToDict) { string[] splitSTR= stringToConvertToDict.Split('&'); var mydictionary = new Dictionary(splitSTR.Length); foreach (string item in splitSTR) { List list = new List(item.Split('=')); mydictionary.Add(list[0], list[1]); } return mydictionary; }
public static Dictionary splitStringToaDictionary(string stringToConvertToDict,char outerSeperator, char innerSeperator) { string[] splitSTR= stringToConvertToDict.Split(outerSeperator); var mydictionary = new Dictionary(splitSTR.Length); foreach (string item in splitSTR) { List list = new List(item.Split(innerSeperator)); mydictionary.Add(list[0], list[1]); } return mydictionary; }
item.Split(new string[] {"#abc#"},StringSplitOptions.None)