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!
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. […]
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.
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”; […]
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.
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 […]
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