Browsing 7239 questions and answers with Jon Skeet

Select 1 field and group by it (my query isnt working)

My query below, what im trying to do is get all the records with that quoteID and then group by that ID var CurSuppliers = db.Quotes_Items_Suppliers.Where(i => i.QuoteID ==...
Jon Skeet
people
quotationmark

Yes, you're getting a list of groups. When you iterate over that, each element of the iteration will be a group - which you can also iterate over. For example: foreach (var group in currentSuppliers) { Console.WriteLine("Group key:... more 1/22/2014 1:06:23 PM

people

Object showing instead of String when received through a stream

Hopefully I don't need to flood this post with my code, but if needed, please ask. Also, I only used getPassword().toString() for testing purposes, and I don't use it in any of my...
Jon Skeet
people
quotationmark

You're calling toString() on a char[]. That doesn't do what you think it does - it will return something like "[C@6af3a631" because arrays don't override toString(). You end up with the default implementation of toString() from Object: ... more 1/22/2014 11:11:01 AM

people

Cannot implicitly convert type error

I have subjected error. Why this error is comming, even I used same thing for my other classes. ActCtrl ctrl = new ActCtrl(); Act action = ctrl.GetAct(companyID, actionID); And...
Jon Skeet
people
quotationmark

You've got two different Act classes - one in the Ent namespace, and one in ERP.Actions.Act. Your action variable is of type ERP.Actions.Act, but ctrl.GetAct is returning an Ent.Act reference. It's not clear what these classes are meant... more 1/22/2014 11:07:56 AM

people

How to know which thread is running my method?

I am using loop to start multiple threads which will execute my method "ThreadFunc". I am giving each thread a name. In my method "ThreadFunc", how to know which thread (thread...
Jon Skeet
people
quotationmark

In my method "ThreadFunc", how to know which thread (thread name) is running my method? Get at the current thread with Thread.CurrentThread, and then just use the Name property: string currentThreadName = Thread.CurrentThread.Name; more 1/22/2014 11:00:05 AM

people

Can I use a post conditional statement with LINQ?

This is how I get my sum double? myVar = myList.Sum(x => x.MyItem); Is-it possible to replace myVar with null if .Sum() return 0 in the same line ? I don't want to...
Jon Skeet
people
quotationmark

It sounds like you want the reverse of the null-coalescing operator, and there's nothing in either LINQ or the C# language to do that for you. You could create your own extension method to do that if you wanted though: public T?... more 1/22/2014 10:32:14 AM

people

Compare String and Object in C#

See this code: object x = "mehdi emrani"; string y = "mehdi emrani"; Console.WriteLine(y == x); that returns true. But this code: object x = "mehdi emrani"; string y = "mehdi...
Jon Skeet
people
quotationmark

In each case, the second operand of == is x, which is of type object. That means you're using the normal reference equality operator. Now in your first case, you're using two string constants with the same contents. The C# compiler will... more 1/22/2014 9:01:59 AM

people

Encryption & Decryption in C#

Here is my code blocks, I assume Decrypt method is not functioning, it returns some garbage value. I am new to this. public string Encrypt(string toEncrypt, string key, bool...
Jon Skeet
people
quotationmark

You're not specifying an IV (initialization vector). The encryption and decryption need to use the same IV. For example, one bad way of doing it would be: tdes.IV = new byte[tdes.BlockSize / 8]; ... in both encryption and decryption.... more 1/22/2014 8:35:29 AM

people

How to resolve class name in static method when accessed through inherited class

I think it is easiest to explain with an example. Let's say I have the following: public class A { public static string DoWork() { return "working" + <here I want the...
Jon Skeet
people
quotationmark

I want the same thing but with the full type name of B. Is it possible? No. A call to B.DoWork is actually compiled into IL for a call to A.DoWork directly. There is no indication in the IL that you actually called B.DoWork, so you... more 1/22/2014 8:10:22 AM

people

FileStream to Bitmap Parameter is not valid

I have read the posts on this subject but none of them explains it to me clearly enough to be able to fix the problem. I am trying to upload a file from a local directory to the...
Jon Skeet
people
quotationmark

There are at least two problems, probably three. First, your copying code is broken: byte[] buffer = new byte[s.Length]; s.Read(buffer, 0, Convert.ToInt32(s.Length)); You've assumed that this will read all of the data in a single Read... more 1/22/2014 7:11:40 AM

people

C# class with optional GUI?

I am looking for a way to have a C# class, primarily run without any sort of GUI as part of a Windows Service to optionally be displayed on a WPF Canvas control. My initial...
Jon Skeet
people
quotationmark

Separate the "business logic" of the class itself from any GUI of it. The GUI should just be a view (possibly with interaction) on top of the business logic. As an example, I recently gave a presentation on "Skeetris" - a block-dropping... more 1/21/2014 8:59:55 PM

people