C#编程技术指南:从入门到精通的全面教程

        无论你是编程新手,还是想要深化.NET技能的开发者,本文都将为你提供一条清晰的学习路径,从C#基础到高级特性,每一站都配有详尽解析和实用示例,旨在帮助你建立坚实的知识体系,并激发你对C#及.NET生态的热情。

目录

第一部分:C#基础——构建你的第一个程序

1. 环境搭建

2. 第一个C#程序

3. 变量、数据类型与控制流

1)变量

2)数据类型

3)控制流

4)条件判断(if语句)

5)循环(for语句)

6)循环(while语句)

7)选择(switch语句)

第二部分:面向对象编程(OOP)——构建模块化的代码世界

  

1、类 (Class)

2、对象 (Object)

对象的创建与使用

3、构造函数 (Constructor)

4、属性 (Property)

5、方法 (Method)

6、继承 (Inheritance)

7、封装 (Encapsulation)

第三部分:高级特性——解锁更高效、更优雅的编程技巧

1、 泛型与集合

1)泛型类

2)泛型方法

3)泛型约束

4)数组 (Array)

5)列表 (List)

6)队列 (Queue)

7)栈 (Stack)

8)字典 (Dictionary)

        9)泛型集合

2、 异常处理

3、Lambda表达式与LINQ

第四部分:并发编程——在多核时代乘风破浪

         1、 多线程与并发

     1)线程基础

     2)线程池

    3)任务并行库 (TPL)

   4)并行循环

   5) 异步编程 (async/await)

2、 并发集合

3、 原子操作

4、委托与事件

5、 线程同步

    1)lock 关键字

   2) Monitor 类

  3) Semaphore 类

第五部分:实战演练——理论到实践的跨越

结语


        C#(发音为“See Sharp”)由微软公司精心打造,是一种现代化的面向对象编程语言。它在.NET平台上运行,旨在提供高效、类型安全的开发体验,广泛应用于Windows桌面应用、Web服务、游戏开发(Unity尤为青睐)、以及跨平台解决方案。让我们一起揭开C#的面纱,逐步掌握其精髓。

第一部分:C#基础——构建你的第一个程序

1. 环境搭建

  • Visual Studio:微软官方提供的全能IDE,适用于从简单到复杂的所有项目。
  • .NET SDK:确保安装最新版,它是运行C#程序的基石。

2. 第一个C#程序

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("你好,C#的世界!");
        }
    }
}

这行简单的输出,标志着你的C#旅程正式启航。

3. 变量、数据类型与控制流

  • 在C#编程语言中,变量、数据类型和控制流是构建程序的基础元素。下面我将详细讲解这些概念,并提供一些示例代码来帮助理解。

    1)变量

    变量是存储数据的基本单元。在C#中,变量必须先声明后使用,并且需要指定其数据类型。

  • int age = 25; // 声明一个整数型变量age并赋值为25
    string name = "Alice"; // 声明一个字符串型变量name并赋值为"Alice"
    double height = 1.75; // 声明一个双精度浮点型变量height并赋值为1.75
    

    2)数据类型

    C#支持多种数据类型,包括基本数据类型和复合数据类型。基本数据类型包括整数类型(如int)、浮点类型(如double)、字符类型(如char)和布尔类型(如bool)。

    int number = 10; // 整数类型
    double pi = 3.14159; // 双精度浮点类型
    char letter = 'A'; // 字符类型
    bool isTrue = true; // 布尔类型
    

    3)控制流

    控制流语句用于控制程序的执行流程,包括条件判断和循环操作。常见的控制流语句有ifforwhileswitch等。

  • 4)条件判断(if语句)

    if语句用于根据条件执行不同的代码块。

    int x = 10;
    if (x > 5)
    {
        Console.WriteLine("x is greater than 5");
    }
    else
    {
        Console.WriteLine("x is not greater than 5");
    }
    
    5)循环(for语句)

    for语句用于重复执行一段代码,直到满足特定条件为止。

    for (int i = 0; i < 5; i++)
    {
        Console.WriteLine("Iteration " + i);
    }
    
    6)循环(while语句)

    while语句用于在条件为真时重复执行一段代码。

    int count = 0;
    while (count < 5)
    {
        Console.WriteLine("Count is " + count);
        count++;
    }
    
    7)选择(switch语句)

    switch语句用于根据变量的值执行不同的代码块。

    int day = 3;
    switch (day)
    {
        case 1:
            Console.WriteLine("Monday");
            break;
        case 2:
            Console.WriteLine("Tuesday");
            break;
        case 3:
            Console.WriteLine("Wednesday");
            break;
        default:
            Console.WriteLine("Other day");
            break;
    }
    

第二部分:面向对象编程(OOP)——构建模块化的代码世界

        C# 是一种面向对象的编程语言,类和对象是其核心概念。类是对象的蓝图或模板,而对象是类的实例。下面我将详细讲解 C# 中的类与对象。

1、类 (Class)

        类是用户定义的数据类型,它包含数据成员(字段)和函数成员(方法、属性、事件等)。类定义了对象的结构和行为。

示例:

public class Person
{
    // 字段
    private string name;
    private int age;

    // 构造函数
    public Person(string name, int age)
    {
        this.name = name;
        this.age = age;
    }

    // 属性
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public int Age
    {
        get { return age; }
        set { age = value; }
    }

    // 方法
    public void SayHello()
    {
        Console.WriteLine($"Hello, my name is {name} and I am {age} years old.");
    }
}

2、对象 (Object)

对象是类的实例,通过类创建对象的过程称为实例化。对象可以访问类中定义的字段、属性和方法。

对象的创建与使用

示例:

class Program
{
    static void Main()
    {
        // 创建对象
        Person person = new Person("Alice", 30);

        // 访问属性
        Console.WriteLine(person.Name); // 输出: Alice
        Console.WriteLine(person.Age);  // 输出: 30

        // 调用方法
        person.SayHello(); // 输出: Hello, my name is Alice and I am 30 years old.

        // 修改属性
        person.Name = "Bob";
        person.Age = 25;

        // 再次调用方法
        person.SayHello(); // 输出: Hello, my name is Bob and I am 25 years old.
    }
}

3、构造函数 (Constructor)

构造函数是类的一种特殊方法,用于初始化对象。构造函数与类同名,没有返回类型。

示例:

public class Person
{
    private string name;
    private int age;

    // 构造函数
    public Person(string name, int age)
    {
        this.name = name;
        this.age = age;
    }

    // 其他成员省略...
}

4、属性 (Property)

属性提供了一种访问和修改字段的机制,它包含 get 和 set 访问器。

示例:

public class Person
{
    private string name;
    private int age;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public int Age
    {
        get { return age; }
        set { age = value; }
    }

    // 其他成员省略...
}

 

5、方法 (Method)

方法是类中定义的函数,用于执行特定的操作。

示例:

public class Person
{
    private string name;
    private int age;

    public void SayHello()
    {
        Console.WriteLine($"Hello, my name is {name} and I am {age} years old.");
    }

    // 其他成员省略...
}

6、继承 (Inheritance)

继承是面向对象编程的一个重要特性,它允许一个类继承另一个类的字段和方法。

示例:

public class Student : Person
{
    private string studentId;

    public Student(string name, int age, string studentId) : base(name, age)
    {
        this.studentId = studentId;
    }

    public string StudentId
    {
        get { return studentId; }
        set { studentId = value; }
    }

    public void Study()
    {
        Console.WriteLine($"{Name} with student ID {studentId} is studying.");
    }
}

class Program
{
    static void Main()
    {
        Student student = new Student("Alice", 20, "12345");
        student.SayHello(); // 输出: Hello, my name is Alice and I am 20 years old.
        student.Study();    // 输出: Alice with student ID 12345 is studying.
    }
}

 

7、封装 (Encapsulation)

封装是将数据和操作数据的方法绑定在一起,并隐藏对象的内部实现细节。C# 通过访问修饰符(如 privatepublicprotected)来实现封装。

示例:

public class Person
{
    private string name;
    private int age;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public int Age
    {
        get { return age; }
        set { age = value; }
    }

    // 其他成员省略...
}

        通过这些示例,你可以看到 C# 中类与对象的基本概念和用法。类是对象的蓝图,而对象是类的实例。类定义了对象的结构和行为,而对象是类的具体实现。继承、封装和多态是面向对象编程的三大特性,它们在 C# 中得到了很好的支持。 

第三部分:高级特性——解锁更高效、更优雅的编程技巧

1、 泛型与集合

C# 中的泛型和集合是两个非常重要的概念,它们极大地增强了代码的灵活性和可重用性。下面我将详细讲解这两个概念。

泛型 (Generics)

泛型允许你在定义类、接口、方法或委托时使用类型参数,从而使这些类型或方法可以在不指定具体类型的情况下工作。泛型提高了代码的重用性,增强了类型安全性,并减少了类型转换的需要。

1)泛型类

示例:

public class GenericClass<T>
{
    private T _value;

    public GenericClass(T value)
    {
        _value = value;
    }

    public T GetValue()
    {
        return _value;
    }
}

class Program
{
    static void Main()
    {
        GenericClass<int> intGeneric = new GenericClass<int>(10);
        Console.WriteLine(intGeneric.GetValue()); // 输出: 10

        GenericClass<string> stringGeneric = new GenericClass<string>("Hello");
        Console.WriteLine(stringGeneric.GetValue()); // 输出: Hello
    }
}
2)泛型方法

示例:

public class GenericMethod
{
    public static void Print<T>(T value)
    {
        Console.WriteLine(value);
    }
}

class Program
{
    static void Main()
    {
        GenericMethod.Print(10); // 输出: 10
        GenericMethod.Print("Hello"); // 输出: Hello
    }
}

 

3)泛型约束

你可以通过泛型约束来限制类型参数必须满足的条件。

示例:

public class GenericClassWithConstraint<T> where T : IComparable<T>
{
    private T _value;

    public GenericClassWithConstraint(T value)
    {
        _value = value;
    }

    public T GetValue()
    {
        return _value;
    }

    public bool IsGreaterThan(T other)
    {
        return _value.CompareTo(other) > 0;
    }
}

class Program
{
    static void Main()
    {
        GenericClassWithConstraint<int> intGeneric = new GenericClassWithConstraint<int>(10);
        Console.WriteLine(intGeneric.IsGreaterThan(5)); // 输出: True
    }
}

 

集合 (Collections)

C# 提供了多种集合类型,用于存储和操作一组对象。这些集合类型包括数组、列表、队列、栈、字典等。

4)数组 (Array)

数组是最基本的集合类型,它具有固定大小。

示例:

int[] numbers = new int[5];
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
numbers[3] = 4;
numbers[4] = 5;

foreach (int number in numbers)
{
    Console.WriteLine(number);
}

 

5)列表 (List)

列表是一种动态数组,它的大小可以动态调整。

示例:

using System.Collections.Generic;

List<int> numbers = new List<int>();
numbers.Add(1);
numbers.Add(2);
numbers.Add(3);
numbers.Add(4);
numbers.Add(5);

foreach (int number in numbers)
{
    Console.WriteLine(number);
}

 

6)队列 (Queue)

队列是一种先进先出 (FIFO) 的数据结构。

示例:

using System.Collections.Generic;

Queue<int> queue = new Queue<int>();
queue.Enqueue(1);
queue.Enqueue(2);
queue.Enqueue(3);

while (queue.Count > 0)
{
    Console.WriteLine(queue.Dequeue());
}
7)栈 (Stack)

栈是一种后进先出 (LIFO) 的数据结构。

示例:

using System.Collections.Generic;

Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);

while (stack.Count > 0)
{
    Console.WriteLine(stack.Pop());
}
8)字典 (Dictionary)

字典是一种键值对集合,可以通过键快速查找值。

示例:

using System.Collections.Generic;

Dictionary<string, int> dictionary = new Dictionary<string, int>();
dictionary.Add("one", 1);
dictionary.Add("two", 2);
dictionary.Add("three", 3);

foreach (var item in dictionary)
{
    Console.WriteLine($"{item.Key}: {item.Value}");
}

9)泛型集合

泛型集合是 C# 中推荐的集合类型,因为它们提供了类型安全性和性能优势。

示例:

using System.Collections.Generic;

List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
Queue<string> queue = new Queue<string>();
queue.Enqueue("first");
queue.Enqueue("second");
Stack<double> stack = new Stack<double>();
stack.Push(1.1);
stack.Push(2.2);
Dictionary<int, string> dictionary = new Dictionary<int, string>
{
    { 1, "one" },
    { 2, "two" },
    { 3, "three" }
};

foreach (int number in numbers)
{
    Console.WriteLine(number);
}

while (queue.Count > 0)
{
    Console.WriteLine(queue.Dequeue());
}

while (stack.Count > 0)
{
    Console.WriteLine(stack.Pop());
}

foreach (var item in dictionary)
{
    Console.WriteLine($"{item.Key}: {item.Value}");
}

通过这些示例,你可以看到泛型和集合在 C# 中的强大功能和灵活性。它们是现代 C# 编程中不可或缺的工具。

2、 异常处理

try
{
    // 尝试访问数组越界
    int[] arr = { 1, 2, 3 };
    Console.WriteLine(arr[3]);
}
catch (IndexOutOfRangeException ex)
{
    Console.WriteLine("数组越界:" + ex.Message);
}

使用try-catch捕获并处理异常,增强程序的健壮性。

3、Lambda表达式与LINQ

List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
var evenNumbers = numbers.Where(n => n % 2 == 0);
foreach (var num in evenNumbers)
{
    Console.WriteLine(num);
}

Lambda表达式让代码更简洁,LINQ则提供了查询数据的强大工具集。

第四部分:并发编程——在多核时代乘风破浪

1、 多线程与并发

        C# 多线程与并发编程技术是现代软件开发中的重要组成部分,它允许开发者创建高效、响应迅速的应用程序。以下是对C#中多线程与并发编程技术的详细介绍:

1)线程基础

在C#中,线程是执行代码的基本单元。可以使用 System.Threading.Thread 类来创建和管理线程。

示例:

using System;
using System.Threading;

class Program
{
    static void Main()
    {
        Thread thread = new Thread(new ThreadStart(DoWork));
        thread.Start();
        Console.WriteLine("Main thread continues.");
    }

    static void DoWork()
    {
        Console.WriteLine("Worker thread is running.");
    }
}

2)线程池

线程池是一种管理线程的机制,它可以重用线程,减少线程创建和销毁的开销。可以使用 ThreadPool 类来使用线程池。

示例:

using System;
using System.Threading;

class Program
{
    static void Main()
    {
        ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork));
        Console.WriteLine("Main thread continues.");
        Thread.Sleep(1000); // 等待工作线程完成
    }

    static void DoWork(object state)
    {
        Console.WriteLine("Worker thread from thread pool is running.");
    }
}

 

3)任务并行库 (TPL)

任务并行库 (Task Parallel Library, TPL) 是 .NET Framework 4.0 引入的一个库,它提供了更高级别的抽象来处理并发和并行编程。

示例:

using System;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        Task task = Task.Run(() => DoWork());
        Console.WriteLine("Main thread continues.");
        task.Wait(); // 等待任务完成
    }

    static void DoWork()
    {
        Console.WriteLine("Task is running.");
    }
}

4)并行循环

TPL 还提供了并行循环的机制,如 Parallel.ForParallel.ForEach,它们可以自动并行化循环操作。

示例:

using System;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        Parallel.For(0, 10, i =>
        {
            Console.WriteLine($"Task {i} is running.");
        });
    }
}

5) 异步编程 (async/await)

异步编程模型 (async/await) 是 C# 5.0 引入的一种编程模式,它使得异步编程更加简单和直观。

示例:

using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        await DoWorkAsync();
        Console.WriteLine("Main thread continues.");
    }

    static async Task DoWorkAsync()
    {
        await Task.Delay(1000); // 模拟异步操作
        Console.WriteLine("Async task is completed.");
    }
}

2、 并发集合

.NET 提供了一些并发集合类,如 ConcurrentQueueConcurrentStackConcurrentDictionary,它们可以在多线程环境下安全地进行操作。

示例:

using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        ConcurrentQueue<int> queue = new ConcurrentQueue<int>();

        Task producer = Task.Run(() =>
        {
            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
                Console.WriteLine($"Enqueued {i}");
            }
        });

        Task consumer = Task.Run(() =>
        {
            int result;
            while (queue.TryDequeue(out result))
            {
                Console.WriteLine($"Dequeued {result}");
            }
        });

        Task.WaitAll(producer, consumer);
    }
}

3、 原子操作

原子操作是不可分割的操作,可以确保在多线程环境下操作的原子性。Interlocked 类提供了一些原子操作方法。

示例:

using System;
using System.Threading;

class Program
{
    static int counter = 0;

    static void Main()
    {
        for (int i = 0; i < 10; i++)
        {
            new Thread(IncrementCounter).Start();
        }
    }

    static void IncrementCounter()
    {
        int newValue = Interlocked.Increment(ref counter);
        Console.WriteLine($"Counter: {newValue}");
    }
}

通过这些技术和工具,C# 开发者可以有效地处理多线程和并发编程,创建高性能、高并发的应用程序。

4、委托与事件

public delegate void MessageHandler(string msg);
public class Publisher
{
    public event MessageHandler NewMessage;

    public void Publish(string message)
    {
        NewMessage?.Invoke(message);
    }
}

委托机制允许你将方法作为参数传递,事件则是基于委托的通信方式,增强了组件之间的解耦。

5、 线程同步

  • lock关键字:防止多个线程同时访问共享资源,避免数据竞争。
  • 其他同步工具:如MonitorSemaphore等,提供了更细致的并发控制手段。

    1)lock 关键字

    lock 关键字用于确保在同一时刻只有一个线程可以进入代码的临界区。

    using System;
    using System.Threading;
    
    class Counter
    {
        private int count = 0;
        private readonly object lockObject = new object();
    
        public void Increment()
        {
            lock (lockObject)
            {
                count++;
                Console.WriteLine($"Count: {count}");
            }
        }
    }
    
    class Program
    {
        static void Main()
        {
            var counter = new Counter();
            for (int i = 0; i < 10; i++)
            {
                new Thread(counter.Increment).Start();
            }
        }
    }
    

    在这个示例中,lock 关键字确保了 count 变量的自增操作是线程安全的。

    2) Monitor 类

    Monitor 类提供了与 lock 关键字类似的功能,但提供了更多的控制选项,如 WaitPulse 方法。

    using System;
    using System.Threading;
    
    class CounterWithMonitor
    {
        private int count = 0;
        private readonly object lockObject = new object();
    
        public void Increment()
        {
            Monitor.Enter(lockObject);
            try
            {
                count++;
                Console.WriteLine($"Count: {count}");
            }
            finally
            {
                Monitor.Exit(lockObject);
            }
        }
    }
    
    class Program
    {
        static void Main()
        {
            var counter = new CounterWithMonitor();
            for (int i = 0; i < 10; i++)
            {
                new Thread(counter.Increment).Start();
            }
        }
    }
    

    在这个示例中,Monitor.EnterMonitor.Exit 方法用于确保 count 变量的自增操作是线程安全的。

    3) Semaphore 类

    Semaphore 类用于控制对一个或多个共享资源的并发访问。它可以限制同时访问资源的线程数量。

    using System;
    using System.Threading;
    
    class SemaphoreExample
    {
        private static Semaphore semaphore = new Semaphore(2, 2); // 允许2个线程同时访问
    
        public void AccessResource(int threadId)
        {
            semaphore.WaitOne();
            try
            {
                Console.WriteLine($"Thread {threadId} is accessing the resource.");
                Thread.Sleep(1000); // 模拟资源访问时间
            }
            finally
            {
                Console.WriteLine($"Thread {threadId} is releasing the resource.");
                semaphore.Release();
            }
        }
    }
    
    class Program
    {
        static void Main()
        {
            var semaphoreExample = new SemaphoreExample();
            for (int i = 0; i < 5; i++)
            {
                int threadId = i;
                new Thread(() => semaphoreExample.AccessResource(threadId)).Start();
            }
        }
    }
    

    在这个示例中,Semaphore 类限制了同时访问资源的线程数量为2个。

    通过这些示例,你可以看到如何在C#中使用不同的同步工具来确保线程安全。选择合适的同步工具取决于具体的应用场景和需求。

第五部分:实战演练——理论到实践的跨越

        选择一个小型项目,如简单的图书管理系统、天气查询应用等,动手实践。从需求分析到编码实现,再到调试部署,每一步都是学习成长的机会。记得利用学到的所有知识:OOP设计、泛型集合、异常处理、多线程等,让理论在实践中开花结果。

结语

        C#及其.NET平台是一个广阔且不断演进的技术宇宙。本文仅是入门与进阶的起点,鼓励你持续探索,如C# 10的新特性、Blazor WebAssembly、.NET MAUI跨平台开发等。参加社区讨论,阅读官方文档,不断实践,你将会发现C#不仅仅是一种语言,它是一种强大的工具,助你创造无限可能。现在,带着这份指南,开启你的C#编程征途吧!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/760056.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

扩展阅读:什么是中断

如果用一句话概括操作系统的原理,那就是:整个操作系统就是一个中断驱动的死循环,用最简单的代码解释如下: while(true){doNothing(); } 其他所有事情都是由操作系统提前注册的中断机制和其对应的中断处理函数完成的。我们点击一下鼠标,敲击一下键盘,执行一个程序,…

马斯克的SpaceX发展历史:从濒临破产到全球领先

本文首发于公众号“AntDream”&#xff0c;欢迎微信搜索“AntDream”或扫描文章底部二维码关注&#xff0c;和我一起每天进步一点点 Space Exploration Technologies Corp.&#xff0c;简称SpaceX&#xff0c;是由埃隆马斯克&#xff08;Elon Musk&#xff09;于2002年创办的一…

观察者模式在金融业务中的应用及其框架实现

引言 观察者模式&#xff08;Observer Pattern&#xff09;是一种行为设计模式&#xff0c;它定义了一种一对多的依赖关系&#xff0c;使得多个观察者对象同时监听某一个主题对象。当这个主题对象发生变化时&#xff0c;会通知所有观察者对象&#xff0c;使它们能够自动更新。…

淀山湖之行随笔

我们仰望清新&#xff0c;但又不得不被世俗所伴。 近日上海开始进入梅雨季节&#xff0c;每天大大小小的雨水不断&#xff0c;整个环境也格外的潮湿&#xff0c;不过已经逐渐习惯这种气候&#xff0c;所谓的见怪不怪。 今日是周日&#xff0c;思绪好久&#xff0c;准备去淀山湖…

混合专家模型(MoE)的前世今生

在文章《聊聊最近很火的混合专家模型&#xff08;MoE&#xff09;》中&#xff0c;我们简单介绍了MoE模型的定义和设计&#xff0c;并且比较了MoE和Dense模型的区别&#xff0c;今天我们继续来回顾一下MoE模型发展的历史和最新的发展现状。 从去年GPT-4发布至今&#xff0c;MoE…

Crontab命令详解:轻松驾驭Linux定时任务,提升系统效率

​&#x1f308; 个人主页&#xff1a;danci_ &#x1f525; 系列专栏&#xff1a;《设计模式》《MYSQL》 &#x1f4aa;&#x1f3fb; 制定明确可量化的目标&#xff0c;坚持默默的做事。 引言&#xff1a; crond是Linux系统中用来定期执行命令或指定程序任务的一种服务或软件…

C++ | Leetcode C++题解之第199题二叉树的右视图

题目&#xff1a; 题解&#xff1a; class Solution { public:vector<int> rightSideView(TreeNode* root) {unordered_map<int, int> rightmostValueAtDepth;int max_depth -1;stack<TreeNode*> nodeStack;stack<int> depthStack;nodeStack.push(ro…

【数据结构】(C语言):二叉搜索树

二叉搜索树&#xff1a; 树不是线性的&#xff0c;是层级结构。基本单位是节点&#xff0c;每个节点最多2个子节点。有序。每个节点&#xff0c;其左子节点都比它小&#xff0c;其右子节点都比它大。每个子树都是一个二叉搜索树。每个节点及其所有子节点形成子树。可以是空树。…

leetCode.98. 验证二叉搜索树

leetCode.98. 验证二叉搜索树 题目描述 代码 /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : val(0), left(nullptr), right(nullptr) {}* TreeNode(int x) : val(x), left(n…

鱼叉式钓鱼

鱼叉式网络钓鱼&#xff1a; 鱼叉式网络钓鱼是一种网络钓鱼形式&#xff0c;它针对特定个人或组织发送定制消息&#xff0c;旨在引发特定反应&#xff0c;例如泄露敏感信息或安装恶意软件。这些攻击高度个性化&#xff0c;使用从各种来源收集的信息&#xff0c;例如社交媒体资…

sky18流水线设计

1.最大时钟频率确定 时钟周期要大于等于组合逻辑的delay&#xff08;最大的那条delay&#xff09; Freq_max(Mhz) 1000/T_delay(ns); 数据吞吐率Throughput Freq_max *Toggle_rate;//Toggle_rate&#xff1a;如两个时钟&#xff0c;输入变一次&#xff0c;就是50%&#xff1b…

【考研408计算机组成原理】微程序设计重要考点指令流水线考研真题+考点分析

苏泽 “弃工从研”的路上很孤独&#xff0c;于是我记下了些许笔记相伴&#xff0c;希望能够帮助到大家 目录 微指令的形成方式 微指令的地址形成方式 对应考题 题目&#xff1a;微指令的地址形成方式 - 断定方式 解题思路&#xff1a; 答题&#xff1a; 分析考点&…

大模型系列课程学习-基于2080TI-22G魔改卡搭建双卡大模型训练平台(双系统)

1.选择合适的硬件配置 再配置电脑之前&#xff0c;需要确认自己需要的显存大小、主板、内存条、电源、散热等核心配件。经过前期调研&#xff0c;选择的硬件配置如下&#xff1a; &#xff08;1&#xff09;主板&#xff1a;华南X99_F8D(DDR4主板)&#xff0c;因为需要支持双卡…

1Panel运维利器:功能详解与实操指南

官网地址:https://1panel.cn/ 1Panel简介 1Panel是杭州飞致云信息科技有限公司旗下产品&#xff0c;是一款现代化、开源的Linux服务器运维管理面板&#xff0c;于2023年3月推出。 名称&#xff1a;1Panel开源Linux面板 所属公司&#xff1a;杭州飞致云信息科技有限公司 编写语…

基于HarmonyOS NEXT开发智能提醒助手

目录 目录 目录 前言 关于HarmonyOS NEXT 智能提醒助手需求分析 智能提醒助手设计 1、系统架构 2、功能模块 智能提醒助手的应用场景 智能提醒助手的竞争力 具体技术实现 未来展望 结束语 前言 随着智能设备的普及和物联网技术的飞速发展&#xff0c;人们对于智能…

忙忙碌碌的混沌之中差点扑了个空而错过年中这条线

文章目录 前言初见端倪混沌初始力不从心心力交瘁拾遗补缺总结 前言 突然意识到过完这个周末已经7月份了&#xff0c;他预示着我的2024年已经过半了&#xff0c;过年回家仿佛还是昨天的事情&#xff0c;怎么转眼间已经到了年中了。心里还是不愿承认这件事&#xff0c;翻开自己2…

Nacos配置中心客户端源码分析(一): 客户端如何初始化配置

本文收录于专栏 Nacos 推荐阅读&#xff1a;Nacos 架构 & 原理 文章目录 前言一、NacosConfigBeanDefinitionRegistrar二、NacosPropertySourcePostProcessor三、AbstractNacosPropertySourceBuilder总结「AI生成」 前言 专栏前几篇文章主要讲了Nacos作为服务注册中心相关…

github主页这样优化,让人眼前一亮

我的主页&#xff08;一之十六&#xff09; 1. 创建与账户ID同名的仓库 注意&#xff1a;记得勾选Add a README file 2. markdown语法自定义README.md 3. 辅助工具 优秀profile&#xff1a;https://zzetao.github.io/awesome-github-profile/动态文字&#xff1a;https://r…

SpringMVC(1)——入门程序+流程分析

MVC都是哪三层&#xff1f;在Spring里面分别对应什么&#xff1f;SpringMVC的架构是什么&#xff1f; 我们使用Spring开发JavaWeb项目&#xff0c;一般都是BS架构&#xff0c;也就是Browser&#xff08;浏览器&#xff09;-Server&#xff08;服务器&#xff09;架构 这种架构…

谷歌开发者新号上架攻略:开发者实战经验分享

前段时间&#xff0c;不少开发者朋友们在纷纷在吐槽新账号没法上架成功。以前谷歌对新号是真的很严格&#xff0c;但现在情况似乎有所好转。 今天&#xff0c;和大家聊聊如何在新号成功上架上“快人一步”&#xff0c;以及怎样增加账号权重提高上架成功率。 首先&#xff0c;我…