C# Archives - All Things DotNetAll Things DotNet
  • Subscribe to this RSS feed
  • Receive updates as soon as they are posted.

C# Category

February 6 , 2021 | | In: ASP.Net, ASP.Net Tips, C#, DotNet General

C# Constructor

When adding a Constructor to a C# class, other than doing it manually, instead, there is a very easy shortcut. just type in the letters ‘ctor’ and then follow it by two tabs. Voila, you have a perfectly formed constructor, including the name and curly braces!

August 19 , 2015 | | In: ASP.Net, ASP.Net Tips, C#

Get Local Computer Name from Website on Server

Let’s say you’re on a computer with which you need a website on a server to have information about. First, you want the computer name you’re on. In my case, I ran the page on the website from a remote computer and I needed a textbox to default to the computer name where I was. […]

September 12 , 2014 | | In: ASP.Net, ASP.Net Tips, C#, DotNet General

Calculating Current Fiscal Year

If you are in a company in which the Fiscal Year does not start January 1st, it might become necessary in your code, to figure out what the actual Fiscal Year is at any point during the year. The following is a method (in C#) which returns a string based on the fact that the […]

I wanted to change the .Net Framework of my C# Windows app. Every site I went to to find out where to change said to right click on the project to get the properties page. Then, I would be able to change it in the ‘Target Framework’ dropdown. I never could see that dropdown.

July 27 , 2013 | | In: ASP.Net, ASP.Net Tips, C#

IIF Equivalent in C#

For those of us who came from a VB background, we know how great the immediate if is (iif). To do this in C#, it’s not so straightforward it seems, at least at first, but it’s just as easy and useful. Here’s how it’s the framework is done in C#: yourBool ? “true” : “false”; […]

February 4 , 2013 | | In: C#, MVC3

Show Webgrid in View Only if Populated

I came across a situation in which I needed the MVC Webgrid on my page, but only after I retrieved the criteria to do a search. Having a LIST in my model for the data to populate the grid, if I put the webgrid in the View, when the View loaded, it threw an error […]

Let’s say you have a generic list: (VB.Net) Dim ProdList As New List(Of String) With ProdList .Add(“Alice Mutton”) .Add(“Chai”) .Add(“Chang”) .Add(“Gravad lax”) End With (C#) List ProdList = new List(Of, String); ProdList.Add(“Alice Mutton”); ProdList.Add(“Chai”); ProdList.Add(“Chang”); ProdList.Add(“Gravad lax”); Then, let’s say you want to loop through those items, one at a time and manipulate each one […]

With a list type control (DropDownList/RadioButtonList, etc.) – you can dynamically select items in the list with a sort of ‘built-in’ find routine. For instance, if you are retrieving an item from a database, and you want to select that item in your list type control, this is the way to do it.

February 6 , 2012 | | In: C#, DotNet General, VB.Net, WinForms Tips

Right Clicking to Select a List Item

Here’s the WinForms scenario: You have a listbox which has a context menu. If you try to right-click and item AND choose from the context menu, normal functionality will not choose the item you are actually selecting with your mouse. Normally, you would need to select the item with the left button and then use […]

September 15 , 2011 | | In: ASP.Net, C#, VB.Net

Function doesn’t return a value on all code paths

When you get a warning in your ASP.Net code, it means just what it says. The full error is usually: “Function (YourFunction) doesn’t return a value on all code paths. A null reference exception could occur at run time when the result is used.”

All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF

If you find this site helpful,
please donate to help keep it online and free

Code 'n' Sprox   DreamTemplate - Web Templates

Follow us on Twitter

Follow AllThingsDotNet on Twitter

Test - The Name: 6936