Skip to content

Category: Coding

Access Modifiers (C# Programming Guide)

All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies. You can use the following access modifiers to specify the accessibility of a type or member when you declare it:

public

The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private

The type or member can be accessed only by code in the same class or struct.

protected

The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal

The type or member can be accessed by any code in the same assembly, but not from another assembly.

protected internal

The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

http://msdn.microsoft.com/en-us/library/ms173121.aspx

Change HTMLEncode In An Autogenerated Gridview

The only way I found to change the HtmlEncode property on a bound column when auto-generating the grid-view.

 

Simple Linq to SQL Insert and Update

 

C# List to DataTable

Don’t recall where I found this but converts List to DataTable.

 

Using C# to check if string contains a string in string array

Pieced this together from stackoverflow… http://stackoverflow.com/questions/2912476/using-c-sharp-to-check-if-string-contains-a-string-in-string-array/2912541#2912541

This checks if stringToCheck contains any one of substrings from stringArray.

If you want to ensure that it contains all the substrings, change Any to All:

 

Regex for Credit Card Numbers

Here is a regular expression for credit card numbers.

Regex for U.S. and Canadian Zip Codes

Below is the regex code for U.S. and Canadian zip codes. I’m don’t remember where I found these but hopefully someone finds them useful.

Remove a character from the end of a string…

The following removes all commas from the end of a string.

BugAid is an extension for Visual Studio

This looks like a promising plugin for Visual Studio. It’s already helped me search for text in a large! object. I also used its comparison features. So far so good. Just need to make the decision whether its worth $49.

You can visit the website here for more information and for the 60 day trial: http://www.bugaidsoftware.com/

BugAid is an extension for Visual Studio that can help you whenever you debug C# code. Using our unique features you can debug faster than ever before and have more time for writing quality code!

 

Redirect to HTTPS – Using URL Rewrite

I needed to redirect a HTTP website to HTTPS. I thought it was part of IIS, and I think it was at some point. Maybe in IIS 7.0.

But here is the code to redirect to HTTPS. I grabbed it from here http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/.

You will also need to install the URL Rewrite module located here: http://www.iis.net/download/urlrewrite.