x=x+1 vs. x +=1

From the MSDN library for +=: Using this operator is almost the same as specifying result = result + expression, except that result is only evaluated once. So they are not identical and that is why x += 1 will be more efficient. Update: I just noticed that my MSDN Library link was to the … Read more

Why does a VB.Net function that returns string only actually return a single character?

Note: this answer was originally written by the OP, Kibbee, as a self-answer. However, it was written in the body of the question, not as an actual separate answer. Since the OP has refused repeated requests by other users, including a moderator, to repost in accordance with site rules, I’m reposting it myself. After trying … Read more

Is there a way to programmatically determine if a font file has a specific Unicode Glyph?

Here’s a pass at it using c# and the windows API. [DllImport(“gdi32.dll”)] public static extern uint GetFontUnicodeRanges(IntPtr hdc, IntPtr lpgs); [DllImport(“gdi32.dll”)] public extern static IntPtr SelectObject(IntPtr hDC, IntPtr hObject); public struct FontRange { public UInt16 Low; public UInt16 High; } public List<FontRange> GetUnicodeRangesForFont(Font font) { Graphics g = Graphics.FromHwnd(IntPtr.Zero); IntPtr hdc = g.GetHdc(); IntPtr hFont … Read more

Select either a file or folder from the same dialog in .NET

Technically, it is possible. The shell dialog used by FolderBrowseDialog has the ability to return both files and folders. Unfortunately, that capability isn’t exposed in .NET. Not even reflection can poke the required option flag. To make it work, you’d have to P/Invoke SHBrowseForFolder() with the BIF_BROWSEINCLUDEFILES flag turned on in BROWSEINFO.ulFlags (value = 0x4000). … Read more

String Interpolation in Visual Studio 2015 and IFormatProvider (CA1305)

You’d use the System.FormattableString or System.IFormattable class: IFormattable ifs = (IFormattable)$”Hello, {name}”; System.FormattableString fss = $”Hello, {name}”; // pass null to use the format as it was used upon initialization above. string ifresult = ifs.ToString(null, CultureInfo.InvariantCulture); string fsresult = fss.ToString(CultureInfo.InvariantCulture); You need to be compiling against Framework 4.6, as the IFormattable and FormattableString are classes … Read more

OpenMappedExeConfiguration vs. OpenExeConfiguration

The difference is explained in the ultimate .NET config resource – Cracking the Mysteries of .NET 2.0 Configuration: OpenExeConfiguration (String) will append “.config” to the filename you provide and load that configuration file. It’s important to note that OpenExeConfiguration(string exePath) is a very misleading method, as the filename does not have to be the filename … Read more

how to add new rows into a datatable vb.net

Here is an example of adding a new row to a datatable that uses AutoIncrement on the first column: Define the table structure: Dim dt As New DataTable dt.Columns.Add(“ID”) dt.Columns.Add(“Name”) dt.Columns(0).AutoIncrement = True Add a New row: Dim R As DataRow = dt.NewRow R(“Name”) = txtName.Text dt.Rows.Add(R) DataGridView1.DataSource = dt