Browsing 7239 questions and answers with Jon Skeet

how to run linq on XxmlElement rather than XElement in C#

How to get the attributes of XmlElement rather than XElement in C# with linq? public string test (XmlElement element) { var enumAttr = from attr in element.Attributes select...
Jon Skeet
people
quotationmark

This is because XmlAttributeCollection only implements IEnumerable rather than IEnumerable<T>. You can just change your query expression to: var enumAttr = from XmlAttribute attr in element.Attributes select attr; which is... more 1/17/2014 10:50:05 AM

people

Are local variables threadsafe?

I have a class like the one below: class Program { static void Main(string[] args) { var outputWindow = new OutputWindow(); var...
Jon Skeet
people
quotationmark

Each method invocation will have a separate set of local variables. However, those variables could refer to objects which other methods also use. For example: public void AppendSomething(StringBuilder builder) { ... more 1/17/2014 10:28:04 AM

people

Opposite of String.IsNullOrEmpty() or an alternative way

I wrote this script, that works: if (String.IsNullOrEmpty(item.Description)) { tbItemInput.Rows.Add(tbRow2); tbItemInput.Rows.Add(tbRow3); ...
Jon Skeet
people
quotationmark

"I get an error" is fairly vague - you would get a NullReferenceException if you used item.Description.Equals("euro")) but this should be fine: if (item.Description == "euro") { tbItemInput.Rows.Add(tbRow4); ... more 1/17/2014 10:20:33 AM

people

Send Cyrillic text through Socket?

I have problem with sending Cyrillic text "УБА221" via C# socket. It turned to "#xxxxx221". Here is xxxxx are 5 strange alphabets I can't copy paste. Server side(receiving...
Jon Skeet
people
quotationmark

Look at how you're encoding the text to send it: byte[] byData = System.Text.Encoding.UTF32.GetBytes(subtext); Now look at how you're decoding the binary data back into text: System.Text.Decoder d =... more 1/17/2014 9:49:58 AM

people

Sharing a variable between method overloads?

I'm a real newbie programmer and I'm trying to make an overload that will share a variable. Basically what I want to do is have a method with one overload that writes an integer...
Jon Skeet
people
quotationmark

No, local variables are purely local to the method in question. It's not really clear what you're trying to achieve, but if you want any state which persists between method calls, you'll need a field, and probably expose it as a... more 1/17/2014 9:38:07 AM

people

Querying XML and updating certain elements

I have an XML file in the following format <?xml version="1.0" ?> <AA someattrib="xyz"> <BB someOtherAttrib="xyz"> <Title></Title> ...
Jon Skeet
people
quotationmark

Well one starting point would be to create a Dictionary<string, XElement> mapping the row ID to the element: var dictionary = doc.Element("AA").Element("BB").Element("CC").Elements("myNode") .ToDictionary(x =>... more 1/17/2014 9:27:40 AM

people

How to call a class from a project to another project without call the DLL as reference in C#?

I have three parts of a project, one is Core(bussiness) project, one is webproject and the last is the test project. I want to call some classes that I saved in one folder from...
Jon Skeet
people
quotationmark

Your question is unclear ("since web project is already refereed into the webproject" for example) but you should really make the web project have a reference to the core project, but not the other way round. The core business logic... more 1/17/2014 8:17:29 AM

people

Does .net framework 3.5 required to install .net framework 4.0?

I'm not cleared in the specification of .NET Framework 4.0. As per my knowledge .net framework 3.0 required .net framework 2.0 and .net framework 3.5 required .net framework 3.0,...
Jon Skeet
people
quotationmark

No, every version of .NET has been standalone. You can install .NET 3.0 with no other version installed, ditto .NET 3.5, ditto 4.0, ditto 4.5 etc. Now there have been fewer versions of the CLR than there have of the .NET framework... more 1/17/2014 7:02:31 AM

people

Date formatting exception unparseable date

I am trying to format dates entered by my application user using SimpleDateFormat but I always get an error: 01/28/2014java.text.ParseException: Unparseable date:...
Jon Skeet
people
quotationmark

As you say, Date1 is of the form MM/dd/yyyy... but you're trying to parse it with a format of yyyy-MM-dd HH:mm:ss. The pattern you parse to the SimpleDateFormat constructor has to match the format of the data itself. (What did you think... more 1/16/2014 11:36:11 PM

people

JList.getSelectedValue().toString() returning null?

I have a jlist that holds a bunch of username strings. I dont have a lot of experience with this, so here is the code making jlist: for (int i = 0; i < usersArray.length; i++)...
Jon Skeet
people
quotationmark

From the docs for JList.getSelectedValue() (emphasis mine): Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list. When multiple items are selected, it is simply the... more 1/16/2014 11:12:54 PM

people