178,284 questions
118
votes
6
answers
78k
views
Deserializing polymorphic json classes without type information using json.net
This Imgur api call returns a list containing both Gallery Image and Gallery Album classes represented in JSON.
I can't see how to deserialize these automatically using Json.NET given that there is ...
117
votes
17
answers
118k
views
What is the difference between a reference type and value type in c#?
Some guy asked me this question couple of months ago and I couldn't explain it in detail. What is the difference between a reference type and a value type in C#?
I know that value types are int, bool,...
662
votes
7
answers
406k
views
How to use HTML Agility pack
How do I use the HTML Agility Pack?
My XHTML document is not completely valid. That's why I wanted to use it. How do I use it in my project? My project is in C#.
1517
votes
23
answers
1.4m
views
LINQ's Distinct() on a particular property
I am playing with LINQ to learn about it, but I can't figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy to do, this is not the question). What I ...
340
votes
9
answers
395k
views
How to implement custom JsonConverter in JSON.NET?
I am trying to extend the JSON.net example given here
http://james.newtonking.com/projects/json/help/CustomCreationConverter.html
I have another sub class deriving from base class/Interface
public ...
2271
votes
76
answers
860k
views
How do I calculate someone's age based on a DateTime type birthday?
Given a DateTime representing a person's birthday, how do I calculate their age in years?
246
votes
10
answers
819k
views
Deserialize JSON with C#
I'm trying to deserialize a Facebook friend's Graph API call into a list of objects. The JSON object looks like:
{"data":[{"id":"518523721","name":"ftyft"},
{"id":"527032438","name":"...
817
votes
31
answers
606k
views
Fastest Way of Inserting in Entity Framework
I'm looking for the fastest way of inserting in Entity Framework.
I'm asking this because of the scenario where you have an active TransactionScope and the insertion is huge (4000+). It can ...
72
votes
4
answers
24k
views
C# variance problem: Assigning List<Derived> as List<Base>
Look at the following example (partially taken from MSDN Blog):
class Animal { }
class Giraffe : Animal { }
static void Main(string[] args)
{
// Array assignment works, but...
Animal[] ...
405
votes
86
answers
151k
views
Use of var keyword in C#
After discussion with colleagues regarding the use of the 'var' keyword in C# 3 I wondered what people's opinions were on the appropriate uses of type inference via var?
For example I rather lazily ...
1214
votes
16
answers
1.1m
views
Collection was modified; enumeration operation may not execute
I can't get to the bottom of this error, because when the debugger is attached, it does not seem to occur.
Collection was modified; enumeration operation may not execute
Below is the code.
This is a ...
491
votes
12
answers
473k
views
How does one parse XML files? [closed]
Is there a simple method of parsing XML files in C#? If so, what?
280
votes
3
answers
286k
views
await vs Task.Wait - Deadlock? [duplicate]
I don't quite understand the difference between Task.Wait and await.
I have something similar to the following functions in a ASP.NET WebAPI service:
public class TestController : ApiController
{
...
361
votes
20
answers
502k
views
Parsing CSV files in C#, with header
Is there a default/official/recommended way to parse CSV files in C#? I don't want to roll my own parser.
Also, I've seen instances of people using ODBC/OLE DB to read CSV via the Text driver, and a ...
1311
votes
10
answers
2.0m
views
Group by in LINQ
Let's suppose if we have a class like:
class Person {
internal int PersonID;
internal string car;
}
I have a list of this class: List<Person> persons;
And this list can have ...
1366
votes
29
answers
1.4m
views
Convert a string to an enum in C#
What's the best way to convert a string to an enumeration value in C#?
I have an HTML select tag containing the values of an enumeration. When the page is posted, I want to pick up the value (which ...
477
votes
34
answers
309k
views
Split List into Sublists with LINQ
Is there any way I can separate a List<SomeObject> into several separate lists of SomeObject, using the item index as the delimiter of each split?
Let me exemplify:
I have a List<SomeObject&...
451
votes
15
answers
405k
views
The calling thread cannot access this object because a different thread owns it
My code is as below
public CountryStandards()
{
InitializeComponent();
try
{
FillPageControls();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "...
243
votes
22
answers
428k
views
MVVM: Tutorial from start to finish?
I'm a C#/Windows Forms programmer with more than 5 years experience. I've been investigating WPF using the MVVM (Model-View-ViewModel) design pattern. I have searched the Internet for tutorials. I ...
739
votes
30
answers
823k
views
Can I set an unlimited length for maxJsonLength in web.config?
I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won't have more than 10 char length), it's exceeding the length and throws the error:
...
157
votes
3
answers
183k
views
How to auto-generate a C# class file from a JSON string [closed]
Given the following JSON object,
form = {
"name": "",
"address": {
"street": "",
"city": "",
"province": "",
"postalCode": "",
"country": ""
},
"phoneDay": "",
"...
1655
votes
42
answers
206k
views
Calculate relative time in C#
Given a specific DateTime value, how do I display relative time, like:
2 hours ago
3 days ago
a month ago
736
votes
20
answers
472k
views
C# difference between == and Equals()
I have a condition in a silverlight application that compares 2 strings, for some reason when I use == it returns false while .Equals() returns true.
Here is the code:
if (((ListBoxItem)lstBaseMenu....
683
votes
18
answers
591k
views
How do you create a custom AuthorizeAttribute in ASP.NET Core?
I'm trying to make a custom authorization attribute in ASP.NET Core. In previous versions it was possible to override bool AuthorizeCore(HttpContextBase httpContext). But this no longer exists in ...
594
votes
18
answers
351k
views
Can't specify the 'async' modifier on the 'Main' method of a console app
I am new to asynchronous programming with the async modifier. I am trying to figure out how to make sure that my Main method of a console application actually runs asynchronously.
class Program
{
...