System


.NET Framework 類別庫
DayOfWeek 列舉型別

指定一週中的星期名稱。

命名空間: System
組件: mscorlib (在 mscorlib.dll 中)

語法

Visual Basic (宣告)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration DayOfWeek
Visual Basic (使用方式)
Dim instance As DayOfWeek
C#
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum DayOfWeek
C++
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class DayOfWeek
J#
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum DayOfWeek
JScript
SerializableAttribute 
ComVisibleAttribute(true) 
public enum DayOfWeek
成員

 成員名稱說明
Supported by the .NET Compact FrameworkFriday表示星期五。 
Supported by the .NET Compact FrameworkMonday表示星期一。 
Supported by the .NET Compact FrameworkSaturday表示星期六。 
Supported by the .NET Compact FrameworkSunday表示星期天。 
Supported by the .NET Compact FrameworkThursday表示星期四。 
Supported by the .NET Compact FrameworkTuesday表示星期二。 
Supported by the .NET Compact FrameworkWednesday表示星期三。 
備註

DayOfWeek 列舉型別 (Enumeration) 表示在日曆中一週的星期名稱,每週有七天。這個列舉型別的範圍從零開始 (指示星期天) 到六 (表示星期六)。

這個列舉型別在您想要擁有強型別 (Strongly Typed) 規格的星期名稱時,會非常有用。例如,這個列舉型別為 DateTime.DayOfWeek 屬性的屬性值型別。

範例

下列範例說明了 DateTime.DayOfWeek 屬性和 DayOfWeek 列舉型別。

Visual Basic
' This example demonstrates the DateTime.DayOfWeek property
Imports System

Class Sample
   Public Shared Sub Main()
      ' Assume the current culture is en-US.
      ' Create a DateTime for the first of May, 2003.
      Dim dt As New DateTime(2003, 5, 1)
      Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}", _
                         dt, dt.DayOfWeek = DayOfWeek.Thursday)
      Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Is Thursday the day of the week for 5/1/2003?: True
'The day of the week for 5/1/2003 is Thursday.
'
C#
// This example demonstrates the DateTime.DayOfWeek property
using System;

class Sample 
{
    public static void Main() 
    {
// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
    DateTime dt = new DateTime(2003, 5, 1);
    Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}", 
                       dt, dt.DayOfWeek == DayOfWeek.Thursday);
    Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek);
    }
}
/*
This example produces the following results:

Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/
C++
// This example demonstrates the DateTime.DayOfWeek property
using namespace System;
int main()
{
   
   // Assume the current culture is en-US.
   // Create a DateTime for the first of May, 2003.
   DateTime dt = DateTime(2003,5,1);
   Console::WriteLine(  "Is Thursday the day of the week for {0:d}?: {1}", dt, dt.DayOfWeek == DayOfWeek::Thursday );
   Console::WriteLine(  "The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek );
}

/*
This example produces the following results:

Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/
J#
// This example demonstrates the DateTime.DayOfWeek property
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        // Assume the current culture is en-US.
        // Create a DateTime for the first of May, 2003.
        DateTime dt = new DateTime(2003, 5, 1);
        Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}", 
            dt, (System.Boolean)(dt.get_DayOfWeek() == DayOfWeek.Thursday));
        Console.WriteLine("The day of the week for {0:d} is {1}.", dt, 
            dt.get_DayOfWeek());
    } //main
} //Sample
/*
This example produces the following results:

Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/
平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0、1.0
請參閱

標記 :


Page view tracker