///
生成 function()
代码)或任何工具项(例如电子邮件 @ Outlook 中的签名),用于遵循 MS 标准编码和文档制作理解从事同一项目的其他联合开发人员。例如:
1. **Default Format**
// Name:
// Author:
// Description: <summary></summary>
// Parameters: <param name="abc"></praram>
// Returned Value: <returns></returns>
2. **New Custom Format**
// Application: <project></project> <version></version>
// Created Developer: <developer></developer>
// Created Date: <date></date>
// Last Modified:
// Last Modified Developer:
// Parameters: <param name="abc"></praram>
// Return Type: <returns></returns>
// Description: <summary></summary>
不确定你的意思是否不是 /// 注释,但这个问题有很多选项:
https://stackoverflow.com/questions/641364/c-sharp-documentation-generator
这里还有这些文章:
http://msdn.microsoft.com/en-us/magazine/dd722812.aspx#id0400027
我们的 VSdocman 是让您自定义默认 XML 注释的工具之一。您可以为每个代码元素类型(方法、属性……)甚至特定名称或类型预先定义注释。它称为“评论模板”。然后在代码编辑器中右键单击并选择“添加 XML 注释”。此外,您还可以使用该工具根据您的评论生成文档(HTML、CHM、docx、VS 帮助等)。
将使您到达您想要的位置。只需将您的自定义评论结构添加到 CDATA
部分即可。
using System;
using System.Threading;
class Program
{
static int[] array = new int[100];
static int count = 0;
static int startCount = 0; // Total count for threads starting from the beginning
static int endCount = 0; // Total count for threads starting from the end
static int thread1Count = 0; // Count for thread 1
static int thread2Count = 0; // Count for thread 2
static int thread3Count = 0; // Count for thread 3
static int thread4Count = 0; // Count for thread 4
static object lockObj = new object();
static void WriteFromStart(int value)
{
var random = new Random();
while (true)
{
lock (lockObj)
{
if (count >= 100) return; // Stop when the array is full
// Find the first available spot from the start
for (int i = 0; i < 100; i++)
{
if (array[i] == 0)
{
array[i] = value;
count++;
startCount++;
if (value == 1) thread1Count++;
if (value == 2) thread2Count++;
Console.WriteLine($"Thread {value} wrote at index {i}, value: {value}");
if (count % 10 == 0)
{
Monitor.PulseAll(lockObj); // Notify Thread 5 to print
}
break; // Break after writing to allow other threads a chance
}
}
}
Thread.Sleep(random.Next(50, 200)); // Random delay to simulate competition
}
}
static void WriteFromEnd(int value)
{
var random = new Random();
while (true)
{
lock (lockObj)
{
if (count >= 100) return; // Stop when the array is full
// Find the first available spot from the end
for (int i = 99; i >= 0; i--)
{
if (array[i] == 0)
{
array[i] = value;
count++;
endCount++;
if (value == 3) thread3Count++;
if (value == 4) thread4Count++;
Console.WriteLine($"Thread {value} wrote at index {i}, value: {value}");
if (count % 10 == 0)
{
Monitor.PulseAll(lockObj); // Notify Thread 5 to print
}
break; // Break after writing to allow other threads a chance
}
}
}
Thread.Sleep(random.Next(50, 500)); // Random delay to simulate competition
}
}
static void PrintArray()
{
lock (lockObj)
{
while (count < 100)
{
Monitor.Wait(lockObj); // Wait until 10 numbers are written
Console.WriteLine("Current array state:");
for (int i = 0; i < 100; i++)
{
Console.Write(array[i] + " ");
}
Console.WriteLine();
}
// Print the final results
Console.WriteLine($"\nTotal from threads 1 and 2 (Start): {startCount}");
Console.WriteLine($"Total from threads 3 and 4 (End): {endCount}");
Console.WriteLine($"Thread 1 wrote: {thread1Count} elements");
Console.WriteLine($"Thread 2 wrote: {thread2Count} elements");
Console.WriteLine($"Thread 3 wrote: {thread3Count} elements");
Console.WriteLine($"Thread 4 wrote: {thread4Count} elements");
}
}
static void Main(string[] args)
{
// Initialize array with zeros
for (int i = 0; i < 100; i++)
{
array[i] = 0;
}
// Create threads for writing
Thread thread1 = new Thread(() => WriteFromStart(1)); // Thread 1 writes 1s from start
Thread thread2 = new Thread(() => WriteFromStart(2)); // Thread 2 writes 2s from start
Thread thread3 = new Thread(() => WriteFromEnd(3)); // Thread 3 writes 3s from end
Thread thread4 = new Thread(() => WriteFromEnd(4)); // Thread 4 writes 4s from end
Thread thread5 = new Thread(PrintArray); // Thread 5 prints array every 10 writes
// Start all threads
thread1.Start();
thread2.Start();
thread3.Start();
thread4.Start();
thread5.Start();
// Wait for threads to complete
thread1.Join();
thread2.Join();
thread3.Join();
thread4.Join();
thread5.Join();
}
}