Questions tagged [c#]

C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.

Filter by
Sorted by
Tagged with
1
vote
2answers
76 views

Flat file column based parser

I implemented a Column-based FLAT parser and generator, where the information is loaded from a base class, which contains the attributes that tell the column size and type. For each line of the flat ...
7
votes
2answers
148 views

Iterate only once using LINQ

Funny thing, the following test works: ...
4
votes
1answer
66 views

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
12
votes
4answers
2k views

C# Toy Robot Simulator

I did this coding exercise for a potential employer who failed it on the basis of unspecified style and structure issues and would appreciate any thoughts on what flaws this contains, in particular in ...
19
votes
4answers
3k views

Matrix class in C#

I've been learning C# during my free time in the past months; before that, I was mostly writing Java, so the transition hasn't been too hard, but I've never had my code reviewed or read by someone ...
3
votes
1answer
75 views

Caching lookup values in an e-commerce website

I am working on an e-commerce website. I have a CarMake dropdown which contains car make names and their corresponding Id, for example: { 1:Alfa romeo}, { 2:Audi }, ...
3
votes
1answer
57 views

Simple winform that randomizes images in a picturebox

I wrote this code for a simple app that gives us random images. The code works, but I feel like I'm doing something wrong. And one thing I would love to know is instead of grabbing from a folder ...
1
vote
0answers
66 views

C# KMP algorithm

I tried to implement KMP algorithm on my own and found it kind of hard to follow. Can you please comment how would you make this code easier to read / understand. ...
2
votes
0answers
49 views

Implementation of SCPI for control of test instruments

I work with electronics test equipment. I like to be able to automate tests using their remote control interfaces. I have built a pattern, a few base classes, that I can apply to all devices that ...
0
votes
1answer
71 views

database connection, fetching rows and handling error in csharp

Fetching database records and displaying as JSON. Asking for revision to ensure if everything's ok, i.e. connections are properly handled and closed in case of error. ...
9
votes
4answers
254 views

Extremely basic login system in console

This is my first C# project. I still am a noob to programming, and while I'm happy I carried out this project, I know that my code needs A LOT of improving and that's why I posted it here. This code ...
7
votes
1answer
304 views

String Format object extension

I wrote an extension to create a string-representation by an object: ...
0
votes
1answer
64 views

Asp.net middleware [closed]

This code is asp.net core middleware written in f# and called from c# for a blazor server-side app. How can this be made more efficient if any in regards to the async code. F#: ...
1
vote
1answer
118 views

Way to check if a byte array contains another byte Array

I'm checking if an byte array contains a another Byte Array with this Code: ...
7
votes
2answers
171 views

LeetCode: Burst Balloons C#

https://leetcode.com/problems/burst-balloons/ Given n balloons, indexed from 0 to n-1, ...
3
votes
1answer
58 views

Check all permutations of generic type parameters

I have a function that takes an object ("token") and three additional parameters of different types ("obj1", "obj2", "obj3"). The object "token" has an 'IsSatisfied' method that may take none, 1, 2, ...
7
votes
1answer
65 views

Loading BitmapImages out of a Zip file

I'm working on a personal project to get better with C#, and as part of that I have a zip file with 20 or so images saved inside. I want to load those images out of the zip file and display them in my ...
1
vote
0answers
547 views

LeetCode: critical connections in a network C# (Tarjan's algorithm)

https://leetcode.com/problems/critical-connections-in-a-network/ Please review for memory and runtime performance. There are n servers numbered from 0 to n-1 connected by undirected server-to-...
1
vote
1answer
44 views

Using nullable properties in a base class for record selection in Table per Hierarchy

I want to be able to list every Transaction associated with a Client in date order. ...
7
votes
4answers
199 views

Code that reads/writes to bytes of an ascii-encoded hex string

Problem Statement Given a hexadecimal string (hascii) and its binary specification (a list of byte field names, their offsets, and byte lengths), design classes to parse all byte-fields, cast bytes ...
1
vote
0answers
76 views

Generics and aggregated evaluation of validation rules

I have a custom system for data validation; it handles anything from method parameters, return values, objects, etc. The core of this system is IValidationRule and ...
1
vote
0answers
103 views

Codility's GenomicRangeQuery solution in C#

I've been learning C# for a few months now, and I've done some basic things in java last year. I made a solution for the problem the title states, this is the task description. Task description ...
3
votes
2answers
103 views

Q: Project Euler #1 - C#

Good day, it's my first time doing something like this so I wanted to solve some of the challenges on project Euler, however I reached a block on my code, even before I submitted I was aware that I ...
3
votes
0answers
61 views

Running a JavaScript program from C# with sandboxing

I am using EdgeJS in my application. The application is used to run a user-provided javascript program from C#. Because we allow execution of user scripts some sandboxing is required. I am using vm2 ...
1
vote
1answer
33 views

Calculate sum of an attribute across multiple repositories

I have multiple repositories that contain userId, paidDate and amount attributes like ...
1
vote
1answer
146 views

Shorten the time it is taking to fill data in an ultragrid

lastbudget and lastactual are both Lists These lists populate 2 columns in an infragistics ultragrid PrevFY Actual_c So the grid has defined datasource already. These 2 columns I added ...
2
votes
1answer
87 views

Interface and inheritance; creating download types for a download manager

I'm creating a download manager in C# (in combination with Unity 2019.1.8, running the .NET 4.x equivalent (MONO) scripting back end). To accomplish this I decided to start using interfaces and class ...
9
votes
1answer
200 views

Operation cancellation

Brevity is for kings as it requires context and context is for kings. Me. GitHub and NuGet How many times you have been writing something like this passing those tedious logger/token parameters? <...
2
votes
1answer
181 views

LeetCode: Rotting Oranges in C#

https://leetcode.com/problems/rotting-oranges/ Please review for coding style in 40 minutes job interview. In a given grid, each cell can have one of three values: the value 0 representing an ...
1
vote
2answers
79 views

LeetCode: Spiral Matrix II C#

https://leetcode.com/problems/spiral-matrix-ii/ Please review for performance, how can this code run faster Given a positive integer n, generate a square matrix filled with elements from 1 to n^2 ...
7
votes
2answers
139 views

Letter Combinations of a phone number using a Dictionary

Problem statement (online source) Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone ...
2
votes
0answers
55 views

Function to match the case of a text as per another text

I am translating a text into another language using Google APIs. Sometimes the translated text returned from the API does not match the case of the text provided - e.g. when translating the text "...
4
votes
1answer
114 views

Chuck Norris Joke Teller

I've created a command line joke teller which makes Chuck Norris jokes after communicating with the Chuck Norris API. It also allows you to generate a random person by communicating to the names API ...
1
vote
1answer
60 views

A GapHelper static class to create unique (non-existing) size restricted names

I am working with a 3th party library which has following interface defined for a processing task: ...
1
vote
0answers
45 views

Anti XSS code encapsulated inside model class, does it belong there?

I had some XSS protection code I wanted to add into my Web API/MVC application, the model that was used to bind was EditLocationViewModel as below. My initial plan ...
2
votes
1answer
71 views

Codility's count passing cars in opposite directions in C#

I programmed a few things in java and now I'm learning C#. I've been doing exercises from Codility. The first 3 or 4 were very difficult to me but now I guess I've got the hang of it. This site ...
3
votes
2answers
93 views

Byte extension methods for common bitwise operations

I'd like to learn how I can optimize the following byte extension methods. I'm targeting .NET Standard 2.0 but I'm curious if there are any ways to go about some of this functionality using features ...
2
votes
0answers
82 views

Stream JSON from Azure Cosmos DB to browser in Web API

I have an HTTP endpoint for returning data directly from Azure Cosmos DB. The endpoint is basically a database access point (this seems like a common case). Since I'm returning the data unmodified, ...
3
votes
2answers
113 views

Parcel size classifier [closed]

I submitted a technical assignment for a job interview process and I am stressing out wondering if my submission was any good. I would like to learn and be a better developer, so please give me ...
2
votes
1answer
81 views

Getting a sum of added cells in an ultragridview

The objective of this code is to add the first 3 cells of a column with the next 9 in another column and then to total out in 2 currencyeditor control (which is like a textbox). Here is a ...
3
votes
0answers
65 views

God-class which controll CNC machine

I have a god-class (GodClass) which work with class-adapter. Class-adapter (OldController) work with old api-class which can't to use directly cause it has bad api with low-level parameters. God-class ...
8
votes
1answer
159 views

Normalize whitespace and describe string

The most valuable of all talents is that of never using two words when one will do. Thomas Jefferson. NuGet and GitHub I found it useful to automatically normalize string content a little bit and ...
5
votes
2answers
112 views

Parsing ~100,000 strings and matching them to various classes

I have an app that takes in "commands" in the form of strings that are parsed, and then passed off to a specific class based on the first word in the string. Every ...
5
votes
2answers
286 views

MaxCounters solution in C# from Codility

I programmed a little in java a while back, and now I'm learning C#.This is the first exercise of "medium" or "respectable" difficulty according to Codility, so I'm pretty pleased of finding out that ...
4
votes
2answers
124 views

Finding which items have at least one common value with other items

I have the following collection : ...
1
vote
0answers
54 views

Getting around CORS error for displaying images on my website

I have my images stored in an S3 bucket and I am serving them from AWS CloudFront. I have created 2 CNAME records for the CloudFront: mywebsite.com and ...
2
votes
1answer
69 views

LeetCode: Queue Reconstruction by Height C#

https://leetcode.com/problems/queue-reconstruction-by-height/ Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers \$(h, k)\$, where \$h\$ ...
4
votes
1answer
79 views

More Efficient Way To Search On-Demand

I need better logic that would allow this search to perform quicker and more efficiently. In XAML, I have a DataGrid and a ...
9
votes
1answer
332 views

Earliest time frog can jump to the other side of a river in C#. Codility's task

I'm new to C#, I programmed a little in java in the past.I had the two previous exercises reviewed here (permCheck, cyclicRotation, with a 100% score, just like this one), and I'm applying what the ...
4
votes
1answer
139 views

Factory pattern for creating embossing machines

I'm working on a program that creates a file for a specific embosser machine (machine that creates plastic bank card for example). I have 3 embosser machines and all of them create different files. ...