C# 获取当前是星期几的两种方法
C#的功能很强大,却没有直接提供面向汉字文化的开发倾向
比如我现在要说的获取当前的星期我提供两种方法:
①,DateTime.Now.DayOfWeek ,查询MSDN可以知道该属性返回的结果是:
//
// 摘要:
// 获取此实例所表示的日期是星期几。
//
// 返回结果:
// 一个 System.DayOfWeek 枚举常数,它指示星期几。该属性值的范围从零(表示星期日)到六(表示星期六)。
public DayOfWeek DayOfWeek
{
get;
}
依据这个我们想见该属性提供了从星期日到星期六的位置,也就是说是枚举,枚举结合数组不就可以提取我们想要的数据了吗!代码如下:
public string Week()
{
string[] weekdays ={ "星期日" ,"星期一" ,"星期二" ,"星期三" ,"星期四" ,"星期五" ,"星期六" };
string week=weekdays[Convert.ToInt32(DateTime.Now.DayOfWeek)];
return week;
}
你只要调用该方法:Week()就可以得到当前星期几的汉字表示 Lable1.Text=Week();
②第二种方法是直接根据星期的数目比较小还可以直接转化,这时候我们可以用switch关键字代码如下:
public string Week(string weekName)
{
string week;
switch(weekName)
{
相关文档:
在C#里创建和使用C风格数据结构,即非托管的数据结构,可以提高性能。
1 数据结构的定义
看下面例子:
unsafe struct A {
public int x;
}
unsafe struct B {
pu ......
C# word转换成HTML
添加com引用Microsoft word 11.0 Object Library
添加using System.Threading;using System.IO;
//实例化一个Word
Microsoft.Office.Interop.Word.ApplicationClass appclass = new Microsoft.Office.Inter ......
Internet 类
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
namespace DownData
{
class internet
{
&nb ......
Paging long articles in ASP.NET using C#
Long articles are better broken into bite-sized chunks over several pages. With static HTML, this is easily achieved by dividing the article into logical separations and creating separate .htm files for each. Here's how to do it using C# for an article that ......
C#与Flash交互 (转自小磊在线)
C#与Flash交互
前段日子公司要求做一个C#与Flash交互的东西,用来C#与短信猫通讯将数据传到Flash上显示与操作的应用。
第一步C#添加组件
打开VS2005-工具-选择工具箱项-COM组件-选择Shockwave Flash Object-确定
添加好组件往场景上拖放,如果提示注册需求注册
c# 注册控件-在运行输 ......