Click here to Skip to main content
15,881,767 members
Everything / Programming Languages / C# 6.0

C# 6.0

C#6.0

Great Reads

by Qwertie
It has 41 features in about 1000 lines of code* - but only 3 lines are needed to parse the expressions you type in. Uses WinForms, BackgroundWorker, GDI+ and LES.
by Ratish Philip
The next version of the useful WPF controls is here
by phil.o
This article describes the building of Markov Chains and their use for generating random names or words.
by Kenneth Haugland
How to connect hot observables to Rx

Latest Articles

by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.

All Articles

Sort by Score

C# 6.0 

12 Jun 2017 by Qwertie
It has 41 features in about 1000 lines of code* - but only 3 lines are needed to parse the expressions you type in. Uses WinForms, BackgroundWorker, GDI+ and LES.
15 Mar 2016 by Ratish Philip
The next version of the useful WPF controls is here
31 Oct 2016 by phil.o
This article describes the building of Markov Chains and their use for generating random names or words.
29 Feb 2016 by Kenneth Haugland
How to connect hot observables to Rx
29 Apr 2019 by Florian Rappl
Why not use serverless computing to perform maintenance tasks in Azure DevOps?
12 Feb 2016 by Kenneth Haugland
Subscribe weakly to an event using Reactive Extensions
23 Mar 2016 by Rubén Hinojosa Chapel
Prototype for a plugin architecture based on the Prism Library and the Modern UI for WPF (MUI) toolkit
8 Apr 2016 by Dmitry Zinchenko
Null-conditional operator in C# 6.0 is not just a mere convenient syntactic sugar.
26 Oct 2016 by Daniel Vaughan
A fun UWP implementation of the game Sokoban, demonstrating some new features of XAML and C# 6.0. Part 3
30 Jun 2017 by Daniel Ziegelmiller
Connecting WPF with Windows Workflow (WF)
2 Nov 2015 by Sibeesh Passion
How to load data from database using Web API
16 Dec 2015 by Bill Wagner
A C# 6 gotcha: Initialization vs. Expression Bodied Members
3 Jan 2017 by Illya Reznykov
WPF datagrid that has same sized dynamically defined number of rows and columns
27 Oct 2015 by Bill Menees
AT&T’s vertical and horizontal coordinates can be used to calculate the latitude and longitude for rate centers and wire centers as well as the distances between them.
19 Apr 2017 by Pankaj Kumar Choudhary
Part 2 of how to set up Angular2 with .NET Core
3 Dec 2016 by axuno
SmartFormat.NET /2 is a string template library that allows you to fill a string with data. Easy to use, fast, extensible, and extremely powerful. Allows for named {placeholders} using any data type, conditional formatting, iterating through IEnumerables, and much more.
2 Mar 2016 by Dave Kreskowiak
Next time, just put the code in the post, not in an image.No, you're wrong about the "8 bytes".The top code snippet in the image is just a shortcut, an "auto-implemented" property. Behind the scenes it's doing exactly the same thing as the second code snippet in the image.In both...
1 Jun 2016 by Matt T Heffron
If you must modify an array in place then when you delete an element, you need to copy all of the following elements down one position, and put the zero at the end position:int [] marks = new int[5] { 1, 2, 3, 4, 5};int deleteAtIndex = 1;for (int i = deleteAtIndex; i
4 Jan 2017 by Illya Reznykov
Data grid cells in WPF with defined fixed size with number of rows and columns updated dynamically
17 Feb 2017 by Mosti16
Use a custom Authorize Attribute which use a own PermissionProvider with custom Permission-Management.
21 Apr 2022 by Richard Deeming
Simple: ^[-+]?\d+(\.\d+)?$ .NET Regular Expressions | Microsoft Docs[^] But depending on your requirements, it would probably be simpler to use decimal.TryParse to test whether the string is a valid number. Edit: Excluding zero is slightly...
28 Aug 2015 by CPallini
You are comparing references to objects (they cannot be equal for differenct objects, even if they contain same data).See here: "Comparing object used as Key in Dictionary"[^].
12 Oct 2015 by jnegron215
This short tip will show you how to extend PayPal's .NET API by adding new members to their objects and page-level functions that will help provide a smooth error-handling experience.
1 Nov 2015 by Suvendu Shekhar Giri
Try this-con = new SqlConnection("server=(local);database=sp;user id=sa;password =******"); con.Open(); cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "P_PB_Getall"; ...
21 Dec 2015 by Richard MacCutchan
A quick scan of the documentation finds https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getname(v=vs.110).aspx[^].
15 Feb 2016 by Ahmed Amer Jaf
Fast n Easy Way to parse Json data
21 Jun 2016 by Kornfeld Eliyahu Peter
PropertyGrid Class (System.Windows.Forms)[^]
6 Jul 2016 by Jochen Arndt
You are passing the vector by value to your Divisor function:void Divisor(int n, vector vec)When calling the function, a new vector instance is created and filled with the data of the passed vector. But the content of the passed vector is not changed.To change the content of the...
22 Jul 2016 by Dave Kreskowiak
You already got the asnwer to this question 2 days ago on your other question, How to create a simple operating system?[^].First, Linux is not a programming language.Second, there is no such thing as "connect the kernel of the system". When writing your own O/S, YOU WRITE THE...
14 Sep 2016 by Suvendu Shekhar Giri
The easiest solution is to change the image url so that everytime it gets an unique URL.Try something like following example -MyImage.ImageUrl ="Images/NewImage1.jpg?" + DateTime.Now.Ticks.ToString();If this doesn't help then let me know.Thanks
27 Sep 2017 by OriginalGriff
Don't do it like that. 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. Use Parametrized queries instead. When you concatenate strings, you cause problems because SQL receives...
5 Jan 2018 by didourebai
How to set up Xamarin Notes environment
31 Jan 2018 by Pawel idzikowski
How to replace the web API request query string to provide case insensitive OData search
6 Jun 2018 by Richard Deeming
If you want to stick with this inefficient approach, you'll need the JSON property names to be prefixed with the "@" character: public class SyncActivity { [JsonProperty("@MemberId")] public string MemberId { get; set; } [JsonProperty("@UserId")] public string UserId { get;...
7 Oct 2018 by Kornfeld Eliyahu Peter
See this case: // project for A.exe namspace A { public class FileFind { // ... } class A { public static void Main(string[] args) { // using FileFind... } } } // project for B.exe namspace B { public class FileFind { // ... } class B { public static...
20 Dec 2018 by Richard Deeming
File.Move will only move a single file; it doesn't know how to process wildcards. You need to list the files you want to move, and move them individually: string sourcePath = @"C:\Users\Chris\Desktop\"; string destinationPath = @"C:\Users\Chris\Documents\Excel\"; foreach (string sourceFile in...
1 Feb 2019 by F-ES Sitecore
Enumerable.Range(1, 31).Select(day => DateTime.Now.AddDays(day)).ToList();
21 Mar 2019 by TheRealSteveJudge
is this possible to reduce the size without losing quality The answer is "No". Downsizing an image means reducing the information it contains. Please have a look at Understanding Digital Image Interpolation[^] There it is said "an image will always lose some quality each time interpolation...
21 Mar 2019 by CPallini
Quote: 'without losing any quality' This is a very strict requirement and TheRealSteveJudge is right, you cannot satisfy it. However, if you relax such a requirement and accept losing some quality then have a look at Libor Tinka's "Image Resizing - outperform GDI+"[^].
21 Mar 2019 by OriginalGriff
There are two forms of "reduced size": file size, which can - sometimes - be reduced without losing quality; and resolution, which can't. Files size can be reduced, if you load a file and save it as a different format - but the target format has to be a lossless compression method, which JPG...
7 Aug 2019 by jimmson
ISynchronizeInvoke is for WinForms, not for WPF. You need to use a bit different approach. You can find more information on this here: winforms - WPF window doesn't implement ISynchronizeInvoke.InvokeRequired ERROR - Stack Overflow[^] c# - How to Use ISynchronizeInvoke interface? - Stack...
30 Aug 2019 by OriginalGriff
Quotes won't help you at all: in C# the quote character delimits single character literal values: 'a', 'B', '1' Putting them round a line of code won't help. So try something like this: string path = @"D:\Test Data\MyFile.txt"; string allTheText = File.ReadAllText(path); The '@' in front of the...
10 Dec 2019 by Maciej Los
The error message is not related to the subject of "trailing zeros". I'd suggest to read this: ALTER TABLE ALTER COLUMN [access-id] failed because one or more objects access this column[^]
21 Apr 2022 by Patrice T
Quote: I have tried so many combination. but no luck. It should not be a matter of luck, but a matter of learning and practicing. Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre -...
12 Mar 2015 by Praveen Kumar Upadhyay
Please check below link. It has very clearly explained reason behind this.http://stackoverflow.com/questions/295833/nullable-type-issue-with-conditional-operator[^]
7 May 2015 by Mostafa Asaduzzaman
How to access configuration variables via dependency injection in MVC 6 - Visual Studio 2015 RC
28 Aug 2015 by OriginalGriff
Um.AlarmMapped is a class, which means that your Dictionary consists of a reference to a class instance, and a reference to a string.So any checking against the dictionary keys to find a matych will compare class references, not class content.So if your dictionary contains these...
18 Jan 2016 by CPallini
The specific errors happens because there is a bug in the following lineQuote:for (int i = 0; i
22 Feb 2016 by Sascha Lefèvre
The method Dictionary.Add(TKey key, TValue value) will throw an exception if you try to insert a second identical key (whereas setting a value via the indexer property (MapToObject[d.Id] = d;) will simply overwrite an existing entry with the same key).So if you do not get an...
18 Mar 2016 by Sascha Lefèvre
The solution is to dynamically build the required expression tree which normally gets done for you "under the hood" by using those LINQ methods.That's a moderately advanced topic but you don't have to do it yourself: There already are several solutions for this which you could use:Build...
27 Apr 2016 by OriginalGriff
You should talk to the people who created it - 3M[^] - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!Almost certainly they will provide a driver and sample software source.
29 Apr 2016 by OriginalGriff
All software based methods are pseudo random: They use a "fixed algorithm" to generate the sequence of "random" numbers and the whole sequence can be repeated by providing the same seed value. The Random class uses the system clock to initialize the sequence when the instance is created, as can...
2 Jun 2016 by George Jonsson
Just for the fun of it you can do it with two regular expressions.int wordCount = Regex.Matches(txtStringName.Value, "\\w+").Count;int charCount = Regex.Matches(txtStringName.Value, "\\w").Count;
22 Jun 2016 by Sergey Alexandrovich Kryukov
That's right, because a singly link is a natural and clear thing.You can go out of this limitation if you develop your own cell type derived from DataGridViewCell. I'm not sure that such UI element would be practically reasonable; you decide.—SA
25 Jun 2016 by OriginalGriff
Indentation helps a lot when you look at code: it means you can see what is goign on a lot more clearly...But a quick glance says that the swap function:void swap(int *i,int *k){int j;// js any temperory element*i=*k;*k=j;}Is not going to work!What value do you put in k each...
28 Jul 2016 by KarstenK
The primary problem is the memory layout in the different runtime, so my first and hard coded advice is to use only native values (int, double and char[]) in such structures. You cant transfer objects!!!The second is to transfer read-only, that mean that each runtime copies the values one by...
4 Sep 2016 by Karthik_Mahalingam
No need to replace the '-' with '/'DateTime StartDate = DateTime.ParseExact(scheduleDates[0], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
23 Sep 2016 by BillW33
First some advice on asking questions. If you have any code at all show what you have done so far. If you really don't know where to start, as you indicate in your question at least give as much detail as you can on what you are trying to accomplish. We can't know exactly what you need unless...
21 Oct 2016 by Patrice T
Quote:Not displaying data which I stored using database in C#Here you 2 questions.Either ypu fail to recover the data, or you fail to display the data.The debugger will show what your code does, it will help you to spot the problem.You should learn to use the debugger as soon as...
12 Jan 2017 by OriginalGriff
Quote:I have searched a lot on google but cant get any helpful material.:sigh:You clearly didn't search too hard...send SMS through my Mobile Phone GSM C# - Google Search[^]
17 Feb 2017 by OriginalGriff
You can define a string variable in the body of a for loop without problems:for (int i = 0; i
20 Feb 2017 by Karthik_Mahalingam
try this protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add("Id"); dt.Columns.Add("Name"); dt.Columns.Add("Description");...
10 Mar 2017 by Karthik_Mahalingam
change the connection string nameSqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SST321ConnectionString"].ConnectionString);
8 May 2017 by CHill60
I would use ExecuteScalar to be more efficient... like this:private void btnNext_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex == -1) return; using (var conn = new SqlConnection(connstring)) { conn.Open(); var cmd = new SqlCommand { ...
11 Sep 2017 by Graeme_Grant
I think that this is what you are trying to do: Tuple> TupleFactory(string value, List values) { return new Tuple>(value, values); } To use: var listOfTuples1 = TupleFactory("test value", new List { "test value 1", "test...
12 Feb 2018 by Maciej Los
Yes, you can use SQL server database to share data and detect data changes to push notification for specific user. See: SqlDependency Class (System.Data.SqlClient)[^] Detecting Changes with SqlDependency | Microsoft Docs[^] Using SqlDependency for data change events[^] Good luck!
12 Feb 2018 by RickZeeland
As SQL Server is not the easiest database to install and manage, I would recommend using PostgreSQL instead, here is an introduction: Using PostgreSQL in your C# (.NET) application (An introduction)[^] Talking about notifications to other users, here is an CodeProject article (take note Maciej...
21 Feb 2018 by OriginalGriff
Let's simplify this a little: private void MyMethod(ref object o) { } private void MyButton_Click(object sender, EventArgs ew) { OleDbDataAdapter da = new OleDbDataAdapter(); MyMethod(ref da); ... Why do you get an error saying: cannot convert from 'ref...
2 Nov 2018 by Richard Deeming
Use HttpFileCollectionBase.GetMultiple[^] to retrieve the list of posted files for each input: IList additionalDocs = Request.Files.GetMultiple("AdditionalDocs"); IList budgetDocs = Request.Files.GetMultiple("BudgetDocs"); IList...
7 Nov 2018 by Afzaal Ahmad Zeeshan
If you want to use C# because, then you have to leave all that pointer luxury with the C++. The core concept of C# was to enable you to have a managed environment, where you only had to write the business logic instead of having to manage the low-level memory and hardware as well. C# itself is...
23 Dec 2018 by Richard MacCutchan
The logic is fairly straightforward: byteArray = // input data numberOfBytes = // length of input data blockSize = 8 offset = 0 WHILE numberOfBytes > 0 DO copybytes(byteArray[offset], destinationAddress, blocksize) // copy a block offset += blockSize ...
29 Jan 2019 by OriginalGriff
The error is pretty explicit: Invalid column name 'GcdId' Compare your production database against your development DB - at a guess you have missing columns that you will need to create and populate.
29 Jan 2019 by CHill60
Your ExecuteScalar command is returning Null (see the comment from @Richard-Deeming) You should check for the null before attempting to cast the return value. A neat way of doing that is as follows: object result = cmdSELECT.ExecuteScalar(); result = (result == DBNull.Value) ? null : result;...
2 Feb 2019 by OriginalGriff
The whole idea of a PrintDocument is that the PrintPage method is used to print the data regardless of the destination. The difference is that for a PrintPreview you do this: PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = myPrintDocument; ppdialog.Show(); And for a "real"...
4 Feb 2019 by OriginalGriff
Well ... SQL Server 2017 Express Edition | Microsoft[^] - it's free, so no licence cost, and you should be developing against an Express version anyway. Developing / testing against the production DB server is a good recipe for "Oh f*ck" moments and production downtime while databases are...
19 Mar 2019 by David_Wimbley
This has been done plenty before, but here is a link to get you started. When we click on a button, SEND EMAIL with SSRS report[^] This is an answer i provided in the past. If you are still stuck, i suggest you research how to make server side calls from HTML on button click using either...
27 Mar 2019 by Florian Rappl, Manuel Römer
Supporting partial PUT (or PATCH) operations in ASP.NET Core with Newtonsoft.Json
4 Apr 2019 by Richard Deeming
It looks like you've created an entity type to represent the values returned from your view, and you've set the Count column as the primary key for that type. EF uses the Identity map pattern[^]. When it tries to load the third row (Count = 2), it thinks that it has already loaded that record....
11 Apr 2019 by CHill60
From the way you have phrased your question it sounds like you need to learn some simple database design techniques. There are plenty of free resources to help you - here is a starting point[^] Basically, each row in your Products table should have a unique identifier - this is often an int...
2 May 2019 by Patrice T
Quote: when ever i run this code it gives error on line which i underline Your code do not behave the way you expect, or you don't understand why ! There is an almost universal solution: Run your code on debugger step by step, inspect variables. The debugger is here to show you what your code...
8 Jul 2019 by OriginalGriff
In addition to using the HasValue and Value properties that have been suggested, you may find this useful: Working with Age: it's not the same as a TimeSpan![^]
17 Jul 2019 by Richard Deeming
Quote: Am i right that this concept is NOT used to ensure UI Responsiveness? No - async / await is great at ensuring UI responsiveness, if used correctly. Things which are CPU-bound, or which run synchronously, can still cause problems. Eg: calling Thread.Sleep on the UI thread will freeze...
26 Aug 2019 by OriginalGriff
At a guess - and a help vampire like yourself should know by now that without the relevant code that is all it can be - you are trying to set a format string on a enum field. When you do that, you can only use the formats it lists in the error message: Enum.ToString Method (System) | Microsoft...
29 Aug 2019 by jimmson
You need to debug your code and find out which property is set to NULL. That is something nobody can do for you, as we don't have any access to your data. By last "interaction" I guess you meant iteration - so I suspect the last item in Model have some property set to NULL while you trying to...
31 Aug 2019 by Thomas Daniels
I can't see the code you use to render the image, but I'm guessing that you create an img tag with as src the API response. D:\Images1\1.jpg is not a file path that will be recognized by your browser. You'll have to use this: file:///D:/Images1/1.jpg But note that if anyone accesses your MVC...
11 Sep 2019 by OriginalGriff
Use string.LastIndexOf and string.Substring: string lastBit = input.Substring(input.LastIndexOf('/'));
9 Oct 2019 by OriginalGriff
In C#, a class can only derive from one base class - which can be abstract or concrete. If none is specified, the class derives directly from Object. MS reasoned that adding multiple inheritance added too much complexity to C# while providing too little benefit. This gives us a problem which is...
9 Oct 2019 by CPallini
You may well use an abstract class instead of an interface. No one prevents you doing that and there possibly will be no harm to our wonderful world. However, as Griff already explained, in C# you cannot have two base classes, so, if your clss should provide, say, two different behaviours, then...
21 Oct 2019 by Andy Lanng
Please, please read the following article: Understanding SQL Injection and Creating SQL Injection Proof ASP.NET Applications[^] I've corrected your code. Not 100% the best way but at least you won't get sql injection issues. private void btnUpdate_Click(object sender, EventArgs e) { ...
21 Oct 2019 by Patrice T
SqlCommand cmdupdate = new SqlCommand("Update EmployeeDetails SET EmpName='" + txtEmpName.Text + "',EmpDesgn='" + txtEmpDegn.Text + "' ,EmpSalary='" + txtSalary.Text + "' where EmpId=" + txtempid.Text + "", con); Not a solution to your question, but another problem you have. Never build an SQL...
6 Nov 2019 by MadMyche
How hard is it to use Google: Google: aspnet mvc cms open source[^]
28 Nov 2019 by Maciej Los
At the first look, i see 3 errors: 1. //missing [s] in url addresss string urlAddressofW = "https://google.com/search?q=" + ADDING; 2. //Google replaces spaces [" "] with [+] ADDING = PureTexttitle.Replace(" ", "+"); 3. //missing [W] in receiveStream if (responseW.StatusCode ==...
20 Dec 2019 by Richard Deeming
You can't nest forms in HTML. Change the target of your outer form, and remove the nested form. Also, remove the onClick method, which simply throws away the form and makes a GET request for the SaveData action. @using (Html.BeginForm("SaveData", "Access")) { @Html.AntiForgeryToken() ...
20 Jan 2020 by OriginalGriff
If Camera.main is null, then just loading it into the debugger (And it doesn't matter if it's a dll or exe, the debugger will work fine) then just finding that out doesn't help you - the problem isn't in that code, it's in the code that executed some time before that code. If you get a null,...
9 Feb 2020 by Dave Kreskowiak
List will always be slower than an array. Your Button_Click method where most of the code is commented out doesn't do anything at all with an array or a list, unless you're testing the Length and Count properties. That's not really a good test. The reason List will always be slower is because...
18 Jul 2020 by OriginalGriff
Because the language designers decided not to allow it. There is a deeper reason for this in that it adds a lot of complexity with not a lot of "real" benefit, and the reason for that is called the Diamond Problem: Multiple inheritance -...
16 Dec 2020 by Richard MacCutchan
Try the documentation: c const pointer - Google Search[^]
17 Dec 2020 by CPallini
const int* var = &v; // var is a pointer to const int, it is initialized with v address int const* var = &v; // var is a pointer to const int, it is initialized with v address const int *const var = &v; // var is a const pointer to const int,...
7 May 2021 by Richard MacCutchan
Your code can be simplified to the following: using System.IO; using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { Dictionary players = new...