General C# concepts
There are several tips and tricks that are common C# developer practices.
- Initialize objects using an object initializer.
- Learn the differences between passing a struct and a class to a method.
- How to use lambda expressions.
- Resolve type name conflicts by using the global namespace alias.
- Use operator overloading.
- Implement and call a custom extension method.
- Even C# programmers may want to use the
My
namespace from VB. - Create a new method for an
enum
type using extension methods.
Class and struct members
You create classes and structs to implement your program. These techniques are commonly used when writing classes or structs.
- Declare auto implemented properties.
- Declare and use read/write properties.
- Define constants.
- Override the
ToString
method to provide string output. - Define abstract properties.
- Use the xml documentation features to document your code.
- Explicitly implement interface members to keep your public interface concise.
- Explicitly implement members of two interfaces.
Working with collections
These articles help you work with collections of data.
Working with strings
Strings are the fundamental data type used to display or manipulate text. These articles demonstrate common practices with strings.
- Compare strings.
- Modify the contents of a string.
- Determine if a string represents a number.
- Use
String.Split
to separate strings. - Combine multiple strings into one.
- Search for text in a string.
Convert between types
You may need to convert an object to a different type.
- Determine if a string represents a number.
- Convert between strings that represent hexadecimal numbers and the number.
- Convert a string to a
DateTime
. - Convert a byte array to an int.
- Convert a string to a number.
- Use pattern matching, the
as
andis
operators to safely cast to a different type. - Define conversion operators for
struct
types. - Determine if a type is a nullable value type.
- Convert between nullable and non-nullable value types.
Equality and ordering comparisons
You may create types that define their own rules for equality or define a natural ordering among objects of that type.
Exception handling
.NET programs report that methods did not successfully complete their work by throwing exceptions. In these articles you'll learn to work with exceptions.
No comments:
Post a Comment