How to loop through a list and filter items starting with 'OO' in C#?

Advertisements I need to loop the List and then extract the specified items which starts with ‘OO’ to New list Here is my code :- List<string> mylist = new List<string>() Mylist.add(“5876575”); Mylist.add(“OO12571”); Mylist.add(“12287324”); Mylist.add(“87665751”); Mylist.add(“97213233”); Mylist.add(“87612222”); Mylist.add(“OO76566”); List<string> matches = new List<string>() matches = myList.Where(x => x[0] == ‘OO’).ToList(); My above code is not working… Read More How to loop through a list and filter items starting with 'OO' in C#?

C# isn't detecting my static Main() for an entry point

Advertisements Visual Studio 2019 is acting like this static void Main() doesn’t exist. using System; namespace Paint { class Program { void static Main(string[] args) { Paint(); } void Paint() { string[] tiles = new string[256]; var newkey = Console.Read(); int paint = Convert.ToInt32(newkey); tiles[paint] = "Test"; Console.WriteLine(tiles[paint]); Console.Beep(); Console.ReadKey(); Paint(); } } } I… Read More C# isn't detecting my static Main() for an entry point

The interface cannot be used as type argument. Static member does not have a most specific implementation in the interface

Advertisements I have the following implementation which uses .NET 7’s static abstract member functionality: public interface IFoo { public static abstract string Bar { get; } } public class Foo : IFoo { public static string Bar => "Bar" } Now, whenever I use the interface as a type parameter to a generic class, I… Read More The interface cannot be used as type argument. Static member does not have a most specific implementation in the interface

Updating a progress bar while awaiting async operation

Advertisements I try to update a progress bar while awaiting a async IO operation. The following code is doing that. Task<string> io = SomeOperationAsync(); while(!io.IsComplete) { progressBar.Value = value // add some progress; await Task.Delay(TimeSpan.FromMilliseconds(200)); } string result = await io; This works quite ok.The Progressbar fills up quite smoothly. But as you see, I… Read More Updating a progress bar while awaiting async operation

How to use custom DateTime string format for time without the date portion?

Advertisements The below code works for all of the custom date format strings except for the ones relating to time. The ToString returns zeroes for any custom format except the ones containing dates. Is it possible to use the custom formats for time in the way that I’m attempting or do I need to do… Read More How to use custom DateTime string format for time without the date portion?

Execution Timed Out (12000 ms) : How can I fix this error

Advertisements When i am trying to solve problem on codewars, get this error. My code passes all the tests but not optimized . Do u have any advice ? Problem : https://www.codewars.com/kata/525e5a1cb735154b320002c8/train/csharp C#: code >Solution : the problem is that you are using a brute-force solution! when you have an algorithmic/mathematics problem you should think… Read More Execution Timed Out (12000 ms) : How can I fix this error