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
0
votes
0answers
5 views

Modifying a legacy enum - adding a none value

Consider the following block of code public enum MyLegacyEnum { ValueOne = 0, ValueTwo = 1, ValueOneAndTwo = 2 } Assuming ...
2
votes
1answer
16 views

LeetCode: Greatest Common Divisor of Strings C#

https://leetcode.com/problems/greatest-common-divisor-of-strings/ For strings S and T, we say "T divides S" if and only if S = T + ... + T (T concatenated with itself 1 or more times) ...
0
votes
1answer
15 views

Small service for hashing and validating passwords, using PBKDF2

As part of a larger authentication/authorization system, I've developed a small .NET Core 3.0 service for hashing passwords using PBKDF2 (with a salt) and validating passwords against a stored hash/...
-1
votes
3answers
46 views

IF statement with multiple AND/OR conditions

I have if statement with many checks. There must be a better way to implement this. Does someone have an idea on how to improve this method? I have many similar methods in production. I would like to ...
2
votes
2answers
79 views

LeetCode: Diameter of Binary Tree

https://leetcode.com/problems/diameter-of-binary-tree/ Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest ...
5
votes
3answers
156 views

C# Bowling Game interview test

I recently interviewed for a software engineering job that requires at least one year of C# and experience with the Microsoft stack. Even though I made it clear at the outset that I had zero ...
-4
votes
0answers
17 views

having errors with makin g a palindrome program with methods? [on hold]

So I'm trying to make a palindrome program that uses the methods reverse(int number) and isPalindrone(int number) and the program rather prints out palindrome or not palindrome, but I'm getting the ...
2
votes
0answers
20 views

File and folder filter for a “last-updated explorer”

Sometimes I save a file somewhere but can't find it after or I install something and want to see what files were added. For this reason, I created a winforms app which only displayes files created/...
4
votes
2answers
59 views

C# Cryptography Interface

C# lacks a common off-the-shelf encryption and decryption interface for dependency injection. Nearly every codebase I've ever opened has a couple of extension methods for hashing strings and so on. ...
2
votes
0answers
26 views

Seekable HTTP response stream wrapper

I created this wrapper to use together with HttpClient streams and ZipArchive. ZipArchive ...
1
vote
2answers
62 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
111 views

Iterate only once using LINQ

Funny thing, the following test works: ...
-2
votes
0answers
17 views

Is there a way to reduce the logic of generically handling webfaultexceptions [on hold]

I have to error detail classes: IntegrationErrorDetail and Error Detail, they don't inherit from each other because of data members on the properties in the classes. I wasn't to know if I can reduce ...
4
votes
1answer
48 views

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
-2
votes
0answers
18 views

balanced curly brackets check from regex in C# [on hold]

I have the following sentence, "Please check for {input1} and {input2} and {input3}. Thank you." I have the following regex to extract everything in braces. ...
12
votes
4answers
1k 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
2k 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
69 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
48 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
49 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
19 views

Split a list collection into n length [closed]

I have a list List which contains 100 records . I would like to split the above list into 3 lists. I tried the below condition ...
1
vote
0answers
41 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 ...
-3
votes
0answers
23 views

Is this a reasonable way to represent a test instrument that supports SCPI? [closed]

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
69 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. ...
7
votes
3answers
138 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 ...
-4
votes
0answers
37 views

Memory Leak fetching data from SQL DB [closed]

I have created a simple Data Fetch method which fetches data from SQL DB. Each time I fetch data by calling this method the memory grows (application pool memory). When I explicitly call ...
-1
votes
0answers
22 views

'Form1 does not contain a definition for 'Form1', and [closed]

I am completing this tutorial: https://www.youtube.com/watch?v=bglYDCdoBCg I have uploaded the code and fixed all the reference errors but am still facing the following: "Form 1' does not contain a ...
-4
votes
0answers
33 views

.xltx to .xlsx file conversion with bytearray and streams [closed]

I´ve written a code that will open a Word template .xltx and then convert it to a word document .xlsx I have put 2 parts of code together an made it work. My goal is to make it better and seek ...
7
votes
1answer
288 views

String Format object extension

I wrote an extension to create a string-representation by an object: ...
0
votes
1answer
43 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
86 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
159 views

LeetCode: Burst Balloons C#

https://leetcode.com/problems/burst-balloons/ Given n balloons, indexed from 0 to n-1, ...
3
votes
1answer
57 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
50 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
110 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-...
7
votes
4answers
180 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
68 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
37 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
95 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
49 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
30 views

Calculate sum of an attribute across multiple repositories

I have multiple repositories that contain userId, paidDate and amount attributes like ...
1
vote
1answer
105 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
80 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
173 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
104 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
73 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
110 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
88 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: ...