Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to generate a custom xml doc, using this class:
[CollectionDataContract(Name="Applications", ItemName="Application")]
public class ApplicationNamesList : List<string> { }
The xml output im aming at should look like this
<Applications>
<Application>...</Application>
<Application>...</Application>
<Application>...</Application>
</Applications>
But once I have a List<string> object and try and cast this to ApplicationNamesList i get an InvalidCastException.
Is there something basic im not getting here?
A List<string> simply isn't a ApplicationNamesList. You would need to do something like this:
var result = new ApplicationNamesList();
result.AddRange(list);
With list being a List<string>.
Sometimes it helps to use real world examples:
Every Porsche ( => ApplicationNamesList) is a car ( => List<string>). But not every car is a Porsche.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
when using StreamReader in C# to load a txt file into a list, i assume that using a simple "If" the string's length is over a particular length, it will add it to the list. can anyone provide C# code for this? this IS homework, but it's NOT a C# class. the instructor would gladly provide this if i asked this specifically. thx.
the txt file is a dictionary of ~280,000 words, one per line. very simple move to turn into a list, but i'm wondering about getting words at least 2 characters long.
Just use LINQ to give you a subset.
List<string> lines = File.ReadLines(filename)
.Where(l => l.Length > specifiedWordLength)
.ToList();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to write this in C#?
Intent intent = new Intent(Intent.ActionSendMultiple, Android.Provider.MediaStore.Images.Media.ExternalContentUri);
handler(intent);
....
void handler(Intent intent)
{
ArrayList<Uri> imageUris = intent.GetParcelableArrayListExtra(Intent.ExtraStream);
...
}
ArrayList is available is c# but it does not have a generic (<T>) form. ArrayList is a list of objects.
What you want is System.Collections.Generic.List<T>
EDIT : In response to comments, try this;
List<Uri> imageUris = new List<Uri>(intent.GetIntegerArrayListExtra(Intent.ExtraStream));
Easy, just use List<Uri>. It's also faster than ArrayList.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need remove all items step by step from list and add removed items to another list, but I need max effective and hithperformance operation. What is whe best practics?
You could use this code and hope that framework'll do the best for you:
public static void MoveItems<T>(List<T> list1, List<T> list2)
{
list2.AddRange(list1);
list1.Clear();
}
list2 = list1.ToList();
list1.Clear();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the C# equivalent for java LinkedList
you can use Linkedlist in c# and this is good example ...
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// Create a new linked list object instance.
LinkedList<string> linked = new LinkedList<string>();
// Use AddLast method to add elements at the end.
// Use AddFirst method to add element at the start.
linked.AddLast("cat");
linked.AddLast("dog");
linked.AddLast("man");
linked.AddFirst("first");
// Loop through the linked list with the foreach-loop.
foreach (var item in linked)
{
Console.WriteLine(item);
}
}
}
C# already has good LinkedList class.
See msdn.
Is it not satisfied your requirement?