Browsing 7239 questions and answers with Jon Skeet

Why there are collection of static constructors in ITypeSymbol instead of one?

Today working with Roslyn I've stumbled on StaticConstructors property of ITypeSymbol and it's declared as ImmutableArray<IMethodSymbol> but as far as I know there could be...
Jon Skeet
people
quotationmark

My guess: partial classes. public partial class Foo { static Foo() {} } public partial class Foo { static Foo() {} } Even though that's not valid code (which I'd previously forgotten) it may need to be represented within... more 11/7/2014 1:03:42 PM

people

Decode and unzip a Base64 encoded and Gziped compressed text

I am trying to read a text from XML node. The text is base 64 encrypted and Gzip compressed. I am trying in the following ways: 1. XmlNodeList nodeDebugs =...
Jon Skeet
people
quotationmark

This is the problem, I suspect: byte[] compressed = System.Text.Encoding.UTF8.GetBytes(childNodes.Item(i).InnerText.Trim()); You said that your data is compressed and then base64-encoded... but your code doesn't use base64 anywhere,... more 11/7/2014 1:01:07 PM

people

Processing on shared variable by parallel tasks

I am beginning with task library. I wrote simple code like private void button1_Click(object sender, EventArgs e) { simpleMost(); } string mesg; void simpleMost() { mesg...
Jon Skeet
people
quotationmark

You have several tasks, each of which is modifying the same shared resource in a non-atomic way. mesg += "\nTask" + a; is effectively: mesg = mesg + "\nTask" + a; ... so if one task reads mesg, then another task writes a new value to... more 11/7/2014 12:56:53 PM

people

C# Out Parameter

Why it is necessary for the out parameter to be assigned to before it leaves the current method? Can someone please elaborate me what is going inside the shell? Thanks in advance.
Jon Skeet
people
quotationmark

Why it is necessary for the out parameter to be assigned to before it leaves the current method? Think of an out parameter as an extra return value. Just as you can't return from a non-void method without specifying the return value,... more 11/7/2014 11:53:32 AM

people

List with two columns using partial search

I have a list with 2 columns and trying to use contains to search partially. Emp contains id and name. var list = new List<Emp>(); list = list.Any(o => o.Contains(new...
Jon Skeet
people
quotationmark

It's not clear what exactly you're trying to do. You might want: list = list.Where(emp => emp.Name == name).ToList(); or perhaps list = list.Where(emp => emp.Name.Contains(name)).ToList(); It's not at all clear why you'd be... more 11/7/2014 10:34:18 AM

people

How to cast double or double array into double array always in C#

I have method which process the double arrays. I am supplying double arrays using keyword params. My problem is sometimesI have to pass doubles as well and I want to use to same...
Jon Skeet
people
quotationmark

Now you've given an example of how you want to call it, I suspect that using dynamic typing may be the simplest approach: public void DoSomething(params object[] values) { foreach (dynamic value in values) { // Overload... more 11/7/2014 10:10:15 AM

people

DateTime.AddDays what value to pass to generate an exception

I have a small utility class that generate a hash code with input data. What class does & its algorithm is not significant to the question but it looks like below: public...
Jon Skeet
people
quotationmark

If you pass in int.MaxValue, that should end up with a value which is outside the representable range for DateTime, whatever the original DateTime is. Sample code, tested on csharppad.com: DateTime.MinValue.AddDays(int.MaxValue); Using... more 11/7/2014 9:40:47 AM

people

parse nested json string in c#

i have json string as {"AccountNo":"345234533466","AuthValue":"{\"TopUpMobileNumber\":\"345234533466\",\"VoucherAmount\":\"100\"}"} to parse this string i have created class...
Jon Skeet
people
quotationmark

I would suggest using two classes - one for the JSON you're actually receiving, and then one for the object model you want to use: public class JsonUserContext { public string AccountNo { get; set; } public string AuthValue { get;... more 11/7/2014 8:20:37 AM

people

Can't find createAccount symbol in BankAccount project

I'm new to Java and creating this class which calls another class named BankAccount, and I'm getting the "cannot find symbol" error when I compile, the method is right below my...
Jon Skeet
people
quotationmark

This is the problem: account = new createAccount(); That's not trying to call a method called createAccount - it's trying to call a constructor of a type called createAccount, and you don't have such a type. You could write: account =... more 11/6/2014 6:35:24 PM

people

unclear reason why duplicate reference is needed

I have a solution that includes 2 projects: class library/ dll (a) console application (c) The dll has a reference to another dll (b) The console application project has...
Jon Skeet
people
quotationmark

In the console application program I create an instance of the logger class. Right - so you're creating an instance of a type which derives from Singleton<T>. (We'll leave aside the design issue of having a singleton you can... more 11/6/2014 10:19:31 AM

people