C# Base Classes
Last Updated: 2001
Long namespace reference can be abbreviated within the use statement so that
if it is necessary to indicate which class from two identically named classes it
is not necessary to re-include the entire namespace path:
using fred = Dave.Brankin.Was.Here;
...
fred.string myString = ...;
System
-
All the primitives, including class, int, string etc.
-
Date and time manipulations:
- DateTime.Now returns current date-time as a DateTime
object from static class method
- DateTime constructor can accept (y, m, d, h, m ,s, ms)
- DateTime object has properties like Year, Month, Day, DayOfWeek etc.
and methods like ToLongString().
- The Math class contains the usual suspects. For example, Math.Sin(radians),
Math.Max(n1, n2) etc.
System.Data
System.IO
- Including file-handling
- File fh = new File(@"C:\temp\temp.txt");
File object has properties like Name, Directory, FullName, IsDirectory,
IsFile, LastWriteTime, Length.
Treats files and folders as same type of object. Expect an
exception to be thrown if you use a file-only property or method on a folder
object or vice versa. Beta 2 has different objects (no longer the
same)
System.Reflection
System.Net
- Network and Internet classes
System.Web
- ASP+ Web pages
- System.Web.HttpUtility.UrlEncode(string) - converts the parameter
to a format suitable for use in a URL, e.g. myLink.NavigateUrl =
"nextPage.aspx?param1=" + System.Web.HttpUtility.UrlEncode(strParm1);
- [Shouldn't be in this section but] A parameter such as the one above can
be extracted in nextPage.aspx as Request.Params["Name"];
System.WinForms
- Classes relating to stand-alone EXEs
System.Win32
- Win32 API stuff (such as registry manipulation)
System.Diagnostics
- Break()
Launches debugger (prompts user to select one if not already loaded)
- Process fred = new Process();
fred.StartInfo.FileName="Notepad.exe";
fred.Start(); // Runs notepad
or
Process myProcess = Process.Start("Notepad");
System.Diagnostics.Debug
- Useful debug functionality, including:
- WriteLine(...) Write an expression/string to the
Output window at run-time
- Assert(bCondition [, strMessage [, strDetailMessage]])