What is the C# equivalent for java LinkedList [closed] - c#

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?

Related

how can i pass 2D list to Parameter of function using delegate [closed]

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
If I have a parameter in function like the following
List<List<string>> StoredProcedureParameter
how can I pass 2D list to StoredProcedureParameter
plus I need to do that inline by using delegate and an anonymous method
delegate { return 2D list to StoredProcedureParameter}
You can use custom delegates Func and Action instead.
Func<List<List<string>>, int> delegateToCall = ( myList) => return StoredProcedureParameter(myList)) ;
replace int by the required data-type(returned by StoredProcedureParameter) except void in Func delegate.
or
if StoredProcedureParameter returns void use Action instead.
Action<List<List<string>>> delegateToCall = ( myList) => return StoredProcedureParameter(myList)) ;

C# How to have it read words and output results [closed]

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
Sorry, I am EXTREMELY NEW to C#. I do not have much experience with code, so keep that in mind. I want to have my console application do something like this example:
Who is the best?
(Text be written here^)
IF the answer is tim, then write "Your right!"
If the answer is NOT tim, then write "Wrong!" and the code doews not advance until the word "tim" is put in
You can use Console.WriteLine to write out text, and Console.ReadLine() to read in the response from the user. A while loop can be used to keep looping until the reponse matches.
I totally agree with the other answers and comments, but for convenience here is the code
public class Program
{
public static void Main()
{
Console.WriteLine("Who is the best?");
var answer = Console.ReadLine();
if (answer.Equals("tim")){
Console.WriteLine("You're right!")
} else {
Console.WriteLine("Wrong!")
}
}
}

ArrayList<Uri> Intent. How to write in C# [closed]

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.

Remove items from one list in another c# with high performance [closed]

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();

cast List object to new object extending List [closed]

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.

Categories