Click here to Skip to main content
15,889,879 members
Everything / Programming Languages / C# 7.0

C# 7.0

C#7.0

Great Reads

by Jeremy Madden
An attempt to introduce some Functional Programming concepts into an OOP domain
by Fred Song (Melbourne)
Angular 7 with .NET Core 2.2 - Global Weather
by koolprasad2003
This article will give you a brief idea about what's new in C# 7.1, 7.2, 7.3, 8.
by honey the codewitch
An LL(1) pull parser and generator that thinks it's an LL(k) parser - with a rich, simple and beautiful EBNF syntax

Latest Articles

by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Illya Reznykov
How to mock & test methods with out parameters
by Vikas Sharma
Build a robust authentication and authorization system using IdentityServer and ASP.NET Core 3.1
by Mirambek Nagashbekov
Demonstration of filter pattern along with pipeline on data driven application

All Articles

Sort by Updated

C# 7.0 

9 Feb 2024 by Graeme_Grant
Here is your problem: T.TryConvertFromChecked(toUnit.CompoundFactor, out var toCompoundFactor) This calls the TryConvertFromChecked in the readonly struct Double. Here is the method: static bool...
9 Feb 2024 by C Pottinger
I am trying to create a class (Measurement) that should mimic the internal C# numeric classes (int, double, float, etc) as closely as possible. To this end I have defined the Measurement class to have its own implementations of the methods used...
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
19 Dec 2023 by Richard Deeming
Since your repository code is swallowing all exceptions - an extremely bad idea, by the way! - the only reason for a NullReferenceException would be that the baseRepository is null. Check the constructor to make sure you've assigned the field...
18 Dec 2023 by A Belal
in Repository Pattern System.NullReferenceException Delete Method System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Microsoft.EntityFrameworkCore StackTrace: at...
18 Dec 2023 by M Imran Ansari
As the error message, the issue is in Delete method. The Delete method attempts to remove an entity from the context using LapShopContext.Set().Remove(entity). However, the error you're encountering is a NullReferenceException, which suggests...
29 Nov 2023 by Richard Deeming
Quote: The sceffold command now looks like this. Scaffold-DbContext -Provider Microsoft.EntityFrameworkCore.SqlServer -Force -OutputDir Model -Connection "Data Source=MSIBeast\SQLEXPRESS";Initial...
29 Nov 2023 by SpiveyC#
Im trying to run the scaffolding command in PMC. Receving an error when running A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - Certifikatkedjan...
27 Nov 2023 by Graeme_Grant
Looks like a copy & paste error. Change: "ConnectionStrings": { "MovieContext": "Server=(localdb)\\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true\"" } to: "ConnectionStrings": { "MovieContext":...
27 Nov 2023 by Ryan Kaia
"ConnectionStrings": { "MovieContext": "Server=(localdb)\\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true\"" } after adding this connection string to my appsettings.json, I tried to "update-database" in the...
18 Nov 2023 by 855
i found a solution of this: public abstract class A { public static string f { get; set; } } public class B : A { public new static string f { get; set; } static B() { f = "B"; } } public class C : A { public...
5 Nov 2023 by A Belal
I have a controller named Categories. I have one form or One View for Create And Edit. Create Action works well, but when I click Edit, the NewRow is added in database. The problem is I want to Edit Row without adding new in database. What I...
3 Nov 2023 by rw-MassimoTamburini
We are building a WPF application using Microsoft.Extensions.DependencyInjection and we would like to change a little bit the structure that we have now. Our WPF pages use viewmodels and communicate with the business logic layer using commands...
3 Nov 2023 by Mikael Anton Kurki
I have recently made a C# WinForm calculator project which fills a single 3x4 block of text boxes. Like so: private void calculate_Click(object sender, EventArgs e) { TextBox[][] textBoxOutputGroups = new[] { new [] {...
2 Nov 2023 by Maxim Kartavenkov
I think your code should be changed like this: for(int j = 1; j 1) { var3 = var3 + (((Math.Abs(7 - j) * (-1)) + 6) * tadd); } int WP = (j - 1) % 4; var S1 = Math.Pow((var2 - var1) * WP, 2); ...
12 Sep 2023 by A Belal
Error An unhandled exception occurred while processing the request. ArgumentNullException: Value cannot be null. (Parameter 'items') Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList..ctor(IEnumerable items, string dataValueField, string...
8 Sep 2023 by Richard MacCutchan
This is the problem: Error An unhandled exception occurred while processing the request. ArgumentNullException: Value cannot be null. (Parameter 'items') So use the debugger to find out where the exception occurs, and why items is null.
6 Sep 2023 by OriginalGriff
Dear Help Vampire: 30 seconds with Google will have told you what the error number means - it did me in less than ten. And then you would have realized that it's not a problem we could even begin to help you with, since it's related to...
6 Sep 2023 by ahmed_sa
I work on unity csharp . i try to execute multi query on sql sever database using async await threading on same time but i get error so How to solve this error please and why this error generated and reasons for that What I have tried: ...
29 Aug 2023 by ahmed_sa
I work on ASP.NET MVC auto complete project. I face issue I can't display Employee Name on input text Id LineManagerName when changing auto complete employeeId. Employee Id represents: @Html.EditorFor(model => model.LineManager, new {...
23 Aug 2023 by OriginalGriff
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead. When you concatenate strings, you cause...
15 Aug 2023 by Graeme_Grant
The Best place to ask questions about Telerik controls is the Telerik Forums[^]. Telerik support is very good at answering this type of question.
15 Aug 2023 by OriginalGriff
Dumping 50K of HTML and a small chunk of unformatted C# on us isn't helpful: nobody is going to wade through that much junk to try and find any slightly relevant parts. Go back to the beginning, work out what parts of the HTML are relevant to...
9 Aug 2023 by Andre Oosthuizen
You can find a step-by-step on how to create the SSIS Package, starting at lesson 1 - MS Learn | Create a new Integration Services project[^] Quote: 1) On the Windows Start menu, search for and select Visual Studio (SSDT). 2) In Visual Studio,...
9 Aug 2023 by ahmed_sa
I have two servers one server have sql server database and another server have db2 database I need to read data from db2 database on server A then after read it insert it into sql server database that exist on server B I use sql server 2017 ...
4 Aug 2023 by maysam_p82
No public constructor is available for type System.Security.Principal.IIdentity UnityConfig File: var container = new UnityContainer(); container.RegisterType(); container.RegisterType();...
4 Aug 2023 by OriginalGriff
Read the error message: No public constructor is available for type System.Security.Principal.IIdentity It means what it says: you cannot construct an instance of that class (or Interface, which is what I suspect it is from the name). We can't...
30 Jul 2023 by ahmed_sa
I work on asp.net core 7 razor page model . I need to use config file appsettings.json to get value of tag inside barcode i will get tag and inside tag I will get text inside tag so file...
19 Jul 2023 by ahmed_sa
Problem How to get last row in date today from zk machine ? i work on application depend on attendance employee on machine i need to depend on log file data on machine to get data i already connect to machine by using csharp and get all data of time attendance but i need to get last row...
18 Jul 2023 by OriginalGriff
This is the same question as you posted yesterday, but with even less information: How do I avoid flicker in maximize or minimize the form[^] And as Andre said yesterday, there isn't enough information in the first question to begin to answer...
13 Jul 2023 by AstroTheDog
Hello there, I am trying to get ram, cpu and disk data from windows server 2012 with a sample code like below; private static void Main(string[] args) { //can you add try catch to this code try { ...
13 Jul 2023 by Dave Kreskowiak
It's telling you the namespace "virtualization\V2" doesn't exist on the machine. You don't have the Hyper-V WMI provider subsystem installed. Go into "Turn Windows Features on or off" to see what you're missing under Hyper-V.
7 Jul 2023 by OriginalGriff
SqlCommand cmd = new SqlCommand($"InsertintoSalesInvoice {InvoiceNum},{ItemId},{qty},{SalePrice},{discount},{AmountAfterDiscount},{Paid},{Remain},{Total},{PaidDate},{CustomerId} ", cn); That's not a valid SQL command, or even close. INSERT INTO...
7 Jul 2023 by A Belal
I want to create invoice Error Is An unhandled exception occurred while processing the request. SqlException: Incorrect syntax near '/'. Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action...
15 Jun 2023 by Tim the Gamer
Suppose I have a list of student objects where a single student has the properties Name, Age and Company properties. I would like to implement extra Comparer interfaces that will allow me to sort a list of students using the Age and company...
15 Jun 2023 by Richard Deeming
Rather than having the class implement the comparison, use external classes implementing IComparer. public abstract class PersonComparer : IComparer { public int Compare(IPerson left, IPerson right) { if (left...
24 May 2023 by Sumith Peringathara
Hi, I have a requirement to get some data from db using WebAPI and send back to user as a JSON string and convert back it to a datatable. I could not find out what is going wrong. Please suggest. JSON string ----------------- "[{\"TestID\":\"1 \",\"WorkOrderID\":\"2 ...
10 Apr 2023 by Tim the Gamer
I have designed a simple elevator program on a windows forms where I have an array of vertical picture boxes on the same horizontal axis. The program accepts input from the user which is the floor number the elevator is currently on. The floors...
10 Apr 2023 by OriginalGriff
First off, try to make your code reflect the real world: if you have an elevator, it starts from the ground floor and goes up to the top floor - so make your array match that: index 0 is the ground floor, Length - 1 is the top floor. That way,...
2 Mar 2023 by ahmed_sa
I work on EF core 7 blazor . I face issue I can't call Details model from application page to get all Data for details model . meaning I need to display details data as list on application page where Header Id = 1 on action GetAllDetails. so...
2 Mar 2023 by eekayonline
Here's an example of how you would fetch that info using the _context you already have available: [HttpGet] public IActionResult GetAllDetails() { // Retrieve all details with HeaderId = 1 var details = _context.Details.Where(d =>...
19 Feb 2023 by ahmed_sa
I work on blazor web application with .Net core 7. i face issue when implement service for get all items using pagination . so on service my issue is can't return ListQueryResult when apply pagination for get all items . my issue exactly on the...
19 Feb 2023 by Richard Deeming
Quote: IQueryable query = _context.ServerNames; The TRecord generic type parameter is most like not in scope on that line. And even if it is, you'd be trying to assign a set of ServerNames objects to a set of TRecord instances....
12 Feb 2023 by ahmed_sa
i work on .net core 2.2� web application� i found class name start up now i need to migrate from .net core 2.2 to .net core 5 so i don't found start up� i found only program class so how to add my code on start up to program�on .net 5 What...
12 Feb 2023 by developer_1605
just try replacing all the services.smtg from startup to builder.services.smtg under the var builder in the program.cs and all the app.smtg under app.UseAuthorization(); in program.cs
21 Jan 2023 by Steveb1307
Hi, I have a table which will be a Master Color Table and therefore I will list around 1800 Colors by PMS number and will also have the Color Hex for each PMS number. I want to dislpay the Color dependent on the Hex in the cell that contains the...
21 Jan 2023 by Graeme_Grant
I am not sure where you want to put it, so here I have it in a div: @Html.Raw(item.ColorHex) UPDATE So this line? @Html.DisplayFor(modelItem =>...
15 Jan 2023 by lalit.mca2006
Hi , I have xml as below , want to read and assign it into list/dictionary 1 abc1 xyz1 ...
15 Jan 2023 by Graeme_Grant
An almost identical question was asked and answered 2 days ago. Rather that repost the same answer here, please click on the following link: View a XML file in xdocument and linq[^]
12 Jan 2023 by Codes DeCodes
I am consuming SOAP services from my application and I get following XMl content as response consuming .wsdl file in my code. Toyota Fortuner Japan ...
9 Jan 2023 by mojtabahakimian
I'm using C# WPF , I have a DataGrid that is bound to an ObservableCollection , I want to keep focus on DataGrid's row when user is entering value with keyboard on DataGrid, I mean when last row is focus after value entered , istead of lost focus...
1 Jan 2023 by Tim the Gamer
I am trying to remove a logo from an image using C# and AForge.NET but my code which I got from open chat gpt does not compile. Please help me complete this code to remove the logo from the image What I have tried: Bitmap...
1 Jan 2023 by OriginalGriff
Generally speaking, code from ChatGPT doesn't compile, and when it does, it doesn't work - we've seen quite a bit of it recently. Removing logos from images is almost certainly in breach of the terms and conditions under which the image was...
30 Dec 2022 by Graeme_Grant
You could write a windows service[^] that stores the date & time every minute in a specific file. Then your reporting app can use that information. UPDATE Maybe you are looking for Logged in/out session information. This may help: How to get...
30 Dec 2022 by DoingWork
I am reading LastBootUpTime by following method but it displays few days old time while I shutdown my PC on daily basis. I know the solution described in this link Windows 10 LastBootUpTime not updating[^] but enforce each user to change system...
30 Dec 2022 by OriginalGriff
The last boot time is probably correct - it's just your idea of what you do with your computer that differs from Windows. With Win 10 / 11 (and maybe earlier, I'm not sure) "shutdown" and "restart" don't do what the name implies, not really -...
29 Dec 2022 by Graeme_Grant
I did a quick google: winform listview group collapse - Google Search[^] and the first search result: ListView hide or collapse selected group [solution] - StackOverflow[^] pointed to an article right here on Code Project that does exactly what...
28 Dec 2022 by Liktor Janos
I like to expand/collapse a WinForm list. Without set anything to subtitle and footer properties, it works. However if I once set any text to subtitle or footer, that never disappear from GUI. 1) By default my groups are collapsed, only headers...
17 Dec 2022 by Graeme_Grant
LiveCharts - LiveCharts2[^] is very simple to use. The documentation is very good with code samples given. From their documentation, ref: samples.bars.withBackground - LiveCharts2[^] 1. ViewModel using CommunityToolkit.Mvvm.ComponentModel;...
17 Dec 2022 by mojtabahakimian
I'm using C# WPF in Visual Studio with .NET Framework 4.7.2 with SQL Server 2019 Database, and using LiveChart What I want I'm looking for easy and good tool for chart in WPF to control these things : ...
10 Dec 2022 by Sascha Manns
Currently i'm trying to upgrade my old blog to .NET 7. While upgrading i thought, i can remove all hardcoded stuff, so everyone can use it. I have the following Program.cs: public static void Main(string[] args) { var builder =...
10 Dec 2022 by CodeGuru84
The error you're seeing is a NullReferenceException, which occurs when you try to access a member of an object that is null. In this case, it looks like the _config field in your SeedData class is null when the UserAsync method tries to access...
10 Dec 2022 by Dave Kreskowiak
Yeah, you missed something. Why is UserAsync (bad name by the way) static when it depends on the fields of the class being initialized before it's called? You never create an instance of the SeedData class, therefor the instance variables never...
10 Dec 2022 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a...
28 Nov 2022 by Member 15680837
I want to connect two different computers one as the client and the other as a server by C# code any one help me? What I have tried: I want to connect two different computers one as the client and the other as a server by C# code any one help me?
28 Nov 2022 by CPallini
I would suggest you starting from Use Sockets to send and receive data over TCP - .NET | Microsoft Learn[^].
24 Nov 2022 by ahmed_sa
I work on csharp webapi .net core 6 i need to pass number integer id with object but i don't know how to do on post man put method request [HttpPut("{id}")] public async Task Update(int id, UpdateItemCommand command) ...
24 Nov 2022 by Richard Deeming
The ID parameter is part of the route. The URL for your request needs to look something like: https://localhost:7235/api/items/42
19 Nov 2022 by mojtabahakimian
I'm using Material design. I created a color picker to choose the color the user wants, after the user chooses the color and theme. I want to save these settings into a text file on the disk. I don't know how can I convert these types to a list...
19 Nov 2022 by Graeme_Grant
Why not serialize to JSON and write as text, then you can read the text and deserialize it to an object. UPDATE Simple example... sample class to be stored and retrieved: public class Theme { public string ForeColor { get; set; } ...
18 Nov 2022 by ahmed_sa
I work on .net 6 i search more on intent between different between web api and restful api but i don't know difference so what is difference between web api and restfull api ? What I have tried: what is difference between web api and restfull...
18 Nov 2022 by Graeme_Grant
Google Search can answer this for you: web api versus restful - Google Search[^]
13 Nov 2022 by mojtabahakimian
In the C# program, I want to display and play a video from within my program in a window. The path that I give to my video source as an internal path of the embed type works in design mode, but it does not display the video when running the...
9 Nov 2022 by ahmed_sa
I work on .net core 6 vs 2022 i see function have telement but i don't know what this mean can you show me please ? and when use it are there are any thing best from using telement What I have tried: public List...
9 Nov 2022 by OriginalGriff
It's not telement, it's TElement: it's a type placeholder that makes the method work with multiple types without you having to code for all of them separately. Generic classes and methods | Microsoft Learn[^] Get used to them, they are a very...
27 Oct 2022 by Grant Mc
I have created a barcode validator, and some of the barcodes we get may be in a format such as (03) 15645 132156464 I would like to remove only spaces and brackets. I do not want to remove anything else, such as Barcode pending Although I can...
27 Oct 2022 by OriginalGriff
Your example as shown doesn;t work: it leaves ")" characters. And a simpler version would be: [\s()] which does it on a character-by-character basis. If you are going to use Regexes, then get a copy of Expresso[^] - it's free, and it examines,...
27 Oct 2022 by Grant Mc
Figured it out. sampleBarcode = Regex.Replace(sampleBarcode, @"\s+|\(+|\)+", "");
26 Oct 2022 by Ahmed Salah Oct2022
namespace program { class program { static void Main(string[] args) { int[] grade = new int[10]; int[] cre = new int[10]; string[] gpa = new string[10]; double[] gs = new...
26 Oct 2022 by George Swan
What I would suggest is to use generic lists rather than arrays as the list size is not a fixed value so you avoid the empty array cell value problem. Rather than have multiple if then else statements in your code you can calculate the results...
25 Oct 2022 by Graeme_Grant
You need to add a test statement in your second loop... for (int i = 0; i
19 Oct 2022 by Member 15803157
I Have A desktop Application with c# I Created An API Called GetAsync it Get's me Some Data From Remote Server (Table Name Is TempData) what I want to do Is To Get My Data Inside New List Of TempData To Preview It Inside Datagridview public...
19 Oct 2022 by Ahmed Elbaz
Just change the return type to List as follows: public static async Task> GetTempData()
11 Oct 2022 by Tharakharish
Could someone suggest on below risk raised by checkMarx tool for ASp.NET Core WebAPI, as application don't send or store any cookies. " Startup.cs application configuration file, at line 21, does not define sensitive application cookies with the...
28 Aug 2022 by Member 11952355
Is there a way to refresh a static string so you don't have restart the application? for ex. refresh the mysql connection string with a new user or password or host i try it like this What I have tried: public static string...
28 Aug 2022 by OriginalGriff
To add to what Dave has said, even if your ConnectionString was a string field instead of a method, you could not change the MySqlConnection object MySqlCore anyway as it is marked as readonly which means it can be altered only at initialization...
28 Aug 2022 by Dave Kreskowiak
First, that is not a "static string". That is a static method that returns a string. All you have to do is call that method again with new parameters to have a new connection string returned. If you're calling that method once and creating a...
18 Aug 2022 by Know Everything
In the link below you will find a binary data file which contains a position for each of 2 million vehicles. Your task is to write a program that can find the nearest vehicle position in the data file to each of the 10 co-ordinates provided...
18 Aug 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
19 Jul 2022 by Member 13809822
Im trying to set a value to a textbox and i have found the HtmlElemnt i need and changed the value of the text box but it seems like the element won't update himself or trigger some lind mof userinput method. the web will say "You must fill this before you can finish" even when you can clearly...
19 Jul 2022 by Николай Каретников
28 Jun 2022 by Udhaya Bharathi
Can any one please help me with the regular expression for any number from 0 to 100 Valid Number 0 0.00 12.123456 100.00 100 Invalid Number -10.12 100.11 101 I referred the below link and modified the RegX value like ...
28 Jun 2022 by Patrice T
I would try something like : ^100(\.0{1,8})?|\d{1,2}(\.\d{1,8})?$ Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre - perldoc.perl.org[^] Here is links to tools to help build RegEx...
28 Jun 2022 by OriginalGriff
Piebald's solution: ((100)|(\d{1,2}(\.\d{1,8})?)) Isn't quite right - it doesn't detect "100.00" as a valid number, and on some systems it assumes that (100) is a numbered capture group. Try this: ^(?100|\d{1,2})(?\.\d{1,8})?$ If...
26 May 2022 by Member 15651762
I am trying to create a survey application and I want to include a likert style survey question, but I cannot seem to find a way to. What I have tried: I have tried using gridview, but that has not worked out
6 May 2022 by Nalini123456
I'm new to ASP.NET. I am wondering how to redirect to an 'index.cshtml' page in ASP.NET. Please help! What I have tried: Response.Redirect("index.cshtml");
10 Apr 2022 by ahmedbelal
i design desktop application for Customer i coding Edit Form Class Customer_Operation has my Functions My Error is Unable to cast object of type 'System.Int32' to type 'System.Byte[]'. i clicked f10 to debug my Application My Error Here || || ||...
10 Apr 2022 by Richard MacCutchan
As you have already been told in your previous question at Unable to cast object of type 'system.int32' to type 'system.byte[]'.[^], you cannot cast an integer value into a byte array. Whatever you are trying to do with that code, it will never work.
6 Apr 2022 by OriginalGriff
Look at the Show_Customer_Image method, and see what it returns. That'll help you work out what the Row[0][0] cell is, and if it's actually a byte array. Use the debugger - it lets you look at the data while your code is running. Hint: it isn't....
6 Apr 2022 by Dave Kreskowiak
Reposting the same question will not change the answers, nor absolve you from actually thinking about what your code is doing. There is only one place in that line of code where you're converting something to an integer, then you're casting that...