Browsing 7239 questions and answers with Jon Skeet

c# Convert.To/FromBase64String confusion

Assuming I have this Method. private static void Example(string data) { Console.WriteLine("Initial : {0}", data); data = data.PadRight(data.Length + 1, '0');...
Jon Skeet
people
quotationmark

Basically, there's no byte array which would be encoded to 10==. If a base64 string ends with ==, that means that the final 4 characters only represent a single byte. So only the first character and the first 2 bits of the second... more 8/21/2014 10:03:33 PM

people

Can't get Data from XML to LINQ in C#

I have XML file quotes.xml. For my Windows Phone Project. <?xml version="1.0" encoding="utf-8" ?> <Motivation> <Quotes> <Quote Category...
Jon Skeet
people
quotationmark

I suspect the problem is that you're creating an instance of Quote, and not overridden ToString in your Quote class. Given that you're currently only pulling out the content anyway, I'd just create a List<string> instead: var quotes... more 8/21/2014 8:23:46 PM

people

C# Dealing with contradictions in string.replace

I'm getting started with C# and programming in general and I've been playing with the "if" statements, arrays and generally getting to grips with things. However, one thing that...
Jon Skeet
people
quotationmark

If you're always replacing one character with another, it's probably simplest to convert it to a char[] and go through it one character at a time, fixing each one appropriately - rather than doing "all the As" and then "all the... more 8/21/2014 4:27:59 PM

people

enter String inside a another string quotes

I need to use a string something like this String x = "return "My name is X" "; We can see the issue is first and second quotes wll be treated as a String in itself , but...
Jon Skeet
people
quotationmark

You just need to escape the double-quote within the string literal: String x = "return \"My name is X\" "; There are other characters which can be escaped like this too - for example: String tab = "before\tafter"; (That's "before",... more 8/21/2014 4:14:40 PM

people

Unable to cast object of type 'System.Reflection.RuntimePropertyInfo' to type 'System.IConvertible'

I am having issues with the following code. I am iterating through a set to see if an object has a certain property type and if so, do some conversion to it. var props =...
Jon Skeet
people
quotationmark

I assume you want to get the value of the property and convert that to a byte, right? Not the property itself... so: var conv = Convert.ToByte(p.GetValue(obj, null)); It seems odd to have it as a byte rather than a bool, admittedly...... more 8/21/2014 3:46:18 PM

people

C# Decrypting a AES256 encrypted file

I'm trying to decrypt a AES256 coded file but I'm getting a corrupted file output. I have a 256bit (64 chars) hex AES key and a 128bit (32 chars) hex IV key that I'm converting...
Jon Skeet
people
quotationmark

The problem is that your original data is binary data, but you're converting it to a string after you've decrypted it. So you just need to change your method to return a byte[], then change the end of your decryption method to: using... more 8/21/2014 3:04:51 PM

people

Saving Base64 encoded CER file to a String

I am currently able to read a Key modulus from a cer file using this code, also found on StackOverflow: X509Certificate cert = null; String source =...
Jon Skeet
people
quotationmark

The problem is that your string literal doesn't have any line breaks. To faithfully represent the original text, you'd need: String cert_1= "-----BEGIN CERTIFICATE-----\n" +... more 8/21/2014 2:45:11 PM

people

How to set objects name if I only have the number of enum

How to set objects name if I only have the number of enum! See in code what I meanm Im bad to explain //Working //Not Working Code public enum CarColor { Red = 0, ...
Jon Skeet
people
quotationmark

The supposedly problematic line already works: // This compiles fine car.CarColorNumber = 0; It wouldn't compile for any integer value other than a constant of 0, however. There's an implicit conversion from a constant value of 0 to any... more 8/21/2014 1:51:21 PM

people

C# Call single method multiple times simultaneously

I have a Method which calls a Web Service. function void SendAsync( object input ) { // Log Time Before Send to WebService (T1) ...... Call WebMethod .... // Log...
Jon Skeet
people
quotationmark

I suspect it is running concurrently - but that the degree of concurrency is being limited by the HTTP connection pool. You might to change ServicePointManager.DefaultConnectionLimit or set it in your app.config with the... more 8/21/2014 1:36:33 PM

people

C# LINQ to Method syntax

Im trying to wrap my head around LINQ statements in C#, Im trying to convert simple queries to the method syntax equivalent. Most examples i've seen are cluttered with other...
Jon Skeet
people
quotationmark

The full details are in the C# language specification, section 7.16. Additionally, I have an article in my Edulinq blog series which you may find simpler to read. However, for your particular case... secondary from calls always end up... more 8/21/2014 12:54:37 PM

people