摘要:可用is运算符检查是否支持接口,用as运算符转换接口,如:
阅读全文
随笔分类 - C#
摘要:如public class Car : MotorVehicle, IDrivable, ISteerable形式,例如:
阅读全文
摘要:/* Example7_6.cs illustrates some of the System.Object class methods*/
using System;
class Example7_6{
class Program
{
static void Main(string[] args)
{
MyStruct st = new MyStruct();
st.X = 50;
Console.WriteLine(st.X);
Console.ReadLine();
}
阅读全文
摘要:/*
Example7_6.cs illustrates some of the System.Object
class methods
*/
using System;
// declare the Car class
阅读全文
摘要:/*
Example6_3.cs illustrates the use of readonly fields
*/
// declare the Car class
public class Car
{
// declare a readonly field
public readonly string make;
// declare a static readonly field
public static readonly int wheels = 4;
// define a constructor
public Car(string make)
{
System.Console.WriteLine("Creating a Car object");
this.make = make;
}
}
阅读全文
摘要:要改变参数的值,可以用引用传值方式(使用ref关键字)
/*
Example5_7.cs illustrates passing parameters by reference
*/
// declare the Swapper class
public class Swapper
阅读全文
摘要:/*
Example4_17.cs illustrates the use of the
#undef, #elif, and #else preprocessor directives
*/
#define DEBUG
#undef DEBUG
#define PRODUCTION
阅读全文
摘要:C#中枚举类型用Enum表示
class Example2_10
{
enum Planets
{
Mercury = 1,
Venus,
Earth,
Mars,
Jupiter,
Saturn,
Uranus,
Neptune,
Pluto
}
阅读全文
摘要:格式化字符
格式化字符 描述
f或F 格式化浮点数
e或E 用指数计数法格式化数字
p或P 格式化百分数
n或N 用逗号分隔符格式化数字
c或C 格式化本地货币值
阅读全文
摘要:C#中也有类似于C++的运算符重载,如下例中Rectangel中的+操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
阅读全文
摘要:密封类和方法对继承和多态进行限制。在希望别人不能改变代码又希望自己使用时,可以在代码中使用密封的类和方法:使用sealed关键字来表示类或方法为密封
using System;
阅读全文
摘要:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
阅读全文
摘要:int变量可以用ToString方法隐式的转换为一个System.Object对象,这个过程叫包装;一个System.Object也可以转换为一个值变量,这个过程叫解包
阅读全文
摘要:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
阅读全文
摘要:在VC#中提供了Registry类、RegistryKey类来实现对注册表的操作。
其中Registry类封装了注册表的七个基本主健:
Registry.ClassesRoot 对应于HKEY_CLASSES_ROOT主键
Registry.CurrentUser 对应于HKEY_CURRENT_USER主键
Registry.LocalMachine 对应于 HKEY_LOCAL_MACHINE主键
Registry.User 对应于 HKEY_USER主键
Registry.CurrentConfig 对应于HEKY_CURRENT_CONFIG主键
Registry.DynDa 对应于HKEY_DYN_DATA主键
Registry.PerformanceData 对应于HKEY_PERFORMANCE_DATA主键
阅读全文