Quick C#(收藏)

Joplin插件实验室:这6个神器让你的开源笔记效率翻倍 本文深入探讨了Joplin插件的强大功能,推荐了6款能显著提升开源笔记效率的神器,包括Backup、Enhancement Suite和Favorites等。这些插件解决了信息碎片化、编辑效率低下和版本焦虑等核心问题,帮助用户构建个性化的工作流,特别适合跨平台笔记的重度用户。 阅读详情

Introduction

C# is a language with the features of C++, programming style like Java, and the rapid application model of Basic. If you already know the C++ language, it will take you less than an hour to quickly go through the syntax of C#. Familiarity with Java will be a plus because the Java program structure, the concept of packages, and garbage collection will definitely help you learn C# more quickly. So while discussing C# language constructs, I will assume that you know C++.

This article dicusses the C# language constructs and features, using code examples in a brief and comrehensive way so that you can, just by having a glance at the code, understand the concepts.

Note: This article is not for C# gurus. There must be some other beginner's articles on C#, but this is yet another one.

The following topics of the C# langauge are discussed:

  • Program Structure
  • Namespaces
  • Data Types
  • Variables
  • Operators and Expressions
  • Enumerations
  • Statements
  • Classes and Structs
  • Modifiers
  • Properties
  • Interfaces
  • Function Parameters
  • Arrays
  • Indexers
  • Boxing and Unboxing
  • Delegates
  • Inheritance and Polymorphism

The following topics are not discussed:

  • Things that are common in C++ and C#
  • Concepts such as garbage collection, threading, file processing, and so forth
  • Data type conversions
  • Exception handling
  • .NET library

Program Structure

Like C++, C# is case-sensitive. The semicolon, ;, is the statement separator. Unlike C++, there are no separate declaration (header) and implementation(cpp) files in C#. All code (class declaration and implementation) is placed in one file with a cs extention.

Have a look at this Hello world program in C#.

using System;

namespace MyNameSpace

{

class HelloWorld

{
    static void Main(string[] args)
    {
        Console.WriteLine ("Hello World");
     }
}

}

Everything in C# is packed into a class and classes in C# are packed into namespaces (just like files in a folder). Like C++, a main method is the entry point of your program. C++'s main function is called "main", whereas C#'s main function starts with a capital M and is named "Main".

There is no need to put a semicolon after a class block or struct definition. It was required in C++, but not in C#.

Namespace

Every class is packaged into a namespace. Namespaces are exactly the same concept as in C++, but in C# we use namespaces more frequently than in C++. You can access a class in a namespace using dot . qualifier. MyNameSpace is the namespace in the hello world program above.

Now, consider that you want to access the HelloWorld class from some other class in some other namespace.

using System;
namespace AnotherNameSpace
{
    class AnotherClass
    {
        public void Func()
        {
            Console.WriteLine ("Hello World");
        }
    }
}

Now, from your HelloWorld class, you can access it as:

using System;
using AnotherNameSpace;    // you will add this using statement
namespace MyNameSpace
{
class HelloWorld
{
    static void Main(string[] args)
    {
        AnotherClass obj = new AnotherClass();
        obj.Func();
    }
}
}

In the .NET library, System is the top-level namespace in which other namespaces exist. By default, there exists a global namespace, so a class defined outside a namespace goes directly into this global namespace; hence, you can access this class without any qualifier.

you can also define nested namespaces.

Using

The #include directive is replaced with the "using" keyword, which is followed by a namespace name. Just as in "using System", above. "System" is the base-level namespace in which all other namespaces and classes are packed. The base class for all object is Object in the System namespace.

Variables

Variables in C# are almost the same as in C++, except for these differences:

  1. Variables in C# (unlike C++) always need to be initialized before you access them; otherwise, you will get a compile time error. Hence, it's impossible to access an uninitialized variable.
  2. You can't access a .dangling. pointer in C#.
  3. An expression that indexes an array beyond its bounds is also not accessible.
  4. There are no global variables or functions in C# and the behavior of globals is acheived through static functions and static variables.

Data Types

All types of C# are derived from a base-class object. There are two types of data types:

  1. Basic/Built-in types
  2. User-defined types

Following is a table that lists built-in C# types:

Type

Bytes

Desc

byte1unsigned byte
sbyte1signed byte
short2signed short
ushort2unsigned short
int4signed integer
uint4unsigned integer
long8signed long
ulong8unsigned long
float4floating point number
double8double precision number
decimal8fixed precision number
stringunicode string
charunicode char
booltrue, falseboolean

Note: Type range in C# and C++ are different; for example, long in C++ is 4 bytes, and in C# it is 8 bytes. Also, the bool type and string types are different than those in C++. Bool accepts only true and false and not any integer.

User-defined types include:

  1. Classes
  2. Structs
  3. Interfaces

Memory allocation of the data types divides them into two types:

  1. Value Types
  2. Reference Types
Value types

Value types are those data types that are allocated in the stack. They include:

  • All basic or built-in types except strings
  • Structs
  • Enum types
Reference type

Reference types are allocated on the heap and are garbage collected when they are no longer being used. They are created using the new operator, and there is no delete operator for these types, unlike in C++, where the user has to explicitely delete the types created using the delete operator. In C#, they are automatically collected by the garbage collector.

Reference types include:

  • Classes
  • Interfaces
  • Collection types such as arrays
  • String

Enumeration

Enumerations in C# are exactly like C++. They are defined through a enum keyword.

Example:

enum Weekdays
{
  Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
}

Classes and Structs

Classes and structs are same as in C++, except in the difference of their memory allocation. Objects of classes are allocated in the heap, and are created using new, where as structs are allocated in the stack. Structs in C# are very light and fast datatypes. For heavy datatypes, you should create classes.

Examples:

struct Date
{
    int day;
    int month;
    int year;
}

class Date
{
    int day;
    int month;
    int year;
    string weekday;
    string monthName;
    public int GetDay()
    {
        return day;
    }
    public int GetMonth()
    {
        return month;
    }
    public int GetYear()
    {
        return year;
    }
    public void SetDay(int Day)
    {
        day = Day ;
    }
    public void SetMonth(int Month)
    {
        month = Month;
    }
    public void SetYear(int Year)
    {
        year = Year;
    }
    public bool IsLeapYear()
    {
        return (year/4 == 0);
    }
    public void SetDate (int day, int month, int year)
    {
    }
    ...
}

Properties

If you familiar with the object-oriented way of C++, you must have an idea of properties. Properties in the above example of the Date class are day, month, and year for which in C++, you write Get and Set methods. C# provides a more convinient, simple, and straightforward way of accessing properties.

So, the above class can be written as:

using System;
class Date
{
    public int Day{
        get {
            return day;
        }
        set {
            day = value;
        }
    }
    int day;

    public int Month{
        get {
            return month;
        }
        set {
            month = value;
        }
    }
    int month;

    public int Year{
        get {
            return year;
        }
        set {
            year = value;
        }
    }
    int year;

    public bool IsLeapYear(int year)
    {
        return year%4== 0 ? true: false;
    }
    public void SetDate (int day, int month, int year)
    {
        this.day   = day;
        this.month = month;
        this.year  = year;
    }
}

Here is the way you will get and set these properties:

class User
{
   public static void Main()
   {
        Date date = new Date();
        date.Day = 27;
        date.Month = 6;
        date.Year = 2003;
        Console.WriteLine("Date: {0}/{1}/{2}", date.Day,
                                               date.Month,
                                               date.Year);
    }
}

Modifiers

You must be aware of public, private, and protected modifers that are commonly used in C++. Here, I will discuss some new modifiers introduced by C#.

readonly

The readonly modifier is used only for the class data members. As the name indicates, the readonly data members can only be read once they are written either directly initializing them or assigning values to them in constructor. The difference between the readonly and const data members is that const requires you to initialize with the declaration, that is directly. See this example code:

class MyClass
{
    const int constInt = 100;    //directly
    readonly int myInt = 5;      //directly
    readonly int myInt2;

    public MyClass()
    {
        myInt2 = 8;              //Indirectly
    }
    public Func()
    {
        myInt = 7;               //Illegal
        Console.WriteLine(myInt2.ToString());
    }

}
sealed

the sealed modifier with a class doesn't let you derive any class from it. So, you use this sealed keyword for the classes that you don't want to be inherited from.

sealed class CanNotbeTheParent
{
    int a = 5;
}
unsafe

You can define an unsafe context in C# by using an unsafe modifier. In the unsafe context, you can write an unsafe code; for example, C++ pointers and so forth. See the following code:

public unsafe MyFunction( int * pInt, double* pDouble)
{
    int* pAnotherInt = new int;
    *pAnotherInt  = 10;
    pInt = pAnotherInt;
    ...
    *pDouble = 8.9;
}

Interfaces

If you have an idea of the COM, you will immediately know what I am talking about. An interface is the abstract base class containing only the function signatures whose implementation is provided by the child class. In C#, you define such classes as interfaces using the interface keyword. .NET is based on such interfaces. In C#, where you can't use multiple class inheritance, which was previously allowed in C++, the essence of multiple inheritance is acheived through interfaces. That's how your child class may implement multiple interfaces.

using System;
interface myDrawing
{
    int originx
    {
        get;
        set;
    }
    int originy
    {
        get;
        set;
    }
    void Draw(object shape);
}

class Shape: myDrawing
{
    int OriX;
    int OriY;

    public int originx
    {
        get{
            return OriX;
        }
        set{
            OriX = value;
        }
    }
    public int originy
    {
        get{
            return OriY;
        }
        set{
            OriY = value;
        }
    }
    public void Draw(object shape)
    {
        ...    // do something
    }

    // class's own method
    public void MoveShape(int newX, int newY)
    {
    .....
    }

}

Arrays

Arrays in C# are much better than in C++. Arrays are allocated in the heap and thus are of the reference type. You can't access an out-of-bound element in an array. So, C# prevents you from that type of bug. Also, some helper functions to iterate array elements are provided. foreach is the statement for such an iteration. The difference between the syntax of the C++ and C# array is:

  • The square brackets are placed after the type and not after the variable name.
  • You create element locations using new operator.

C# supports single dimensional, multi dimensional, and jagged array (array of an array).

Examples:

    int[] array = new int[10];              // single-dimensional
                                            // array of int
    for (int i = 0; i < array.Length; i++)
        array[i] = i;

    int[,] array2 = new int[5,10];          // 2-dimensional array
                                            // of int
    array2[1,2] = 5;

    int[,,] array3 = new int[5,10,5];       // 3-dimensional array
                                            // of int
    array3[0,2,4] = 9;

    int[][] arrayOfarray = = new int[2];    // Jagged array -
                                            // array of array of
                                            // int
    arrayOfarray[0] = new int[4];
    arrayOfarray[0] = new int[] {1,2,15};

Indexers

An indexer is used to write a method to access an element from a collection using the straight way of using [], like an array. All you need is to specify the index to access an instance or element. The syntax of an indexer is same as that of class properties, except they take the input parameter, that is the index of the element.

Example:

Note: CollectionBase is the library class used for making collections. List is the protected member of CollectionBase, which stores the collection list.
class Shapes: CollectionBase
{
    public void add(Shape shp)
    {
        List.Add(shp);
    }

    //indexer
    public Shape this[int index]
    {
        get {
            return (Shape) List[index];
        }
        set {
            List[index] = value ;
         }
     }
}

Boxing/Unboxing

The idea of boxing is new in C#. As mentioned above, all data types, built-in or user defined, are derived from a base class object in the System namespace. So, the packing of basic or primitive types into an object is called boxing, whereas the reverse of this known as unboxing.

Example:

class Test
{
   static void Main()
   {
      int myInt = 12;
      object obj = myInt ;       // boxing
      int myInt2 = (int) obj;    // unboxing
   }
}

The example shows both boxing and unboxing. An int value can be converted to an object and back again to an int. When a variable of a value type needs to be converted to a reference type, an object box is allocated to hold the value, and the value is copied into the box. Unboxing is just the opposite. When an object box is cast back to its original value type, the value is copied out of the box and into the appropriate storage location.

Function Parameters

Parameters in C# are of three types:

  1. By-Value/In parameters
  2. By-Reference/In-Out parameters
  3. Out pParameters

If you have an idea of the COM interface and its parameters types, you will easily understand the C# parameter types.

By-Value/In parameters

The concept of value parameters is the same as in C++. The value of the passed value is copied into a location and is passed to the function.

Example:

SetDay(5);
...
void SetDay(int day)
{
    ....
}
By-Reference/In-Out Parameters

The reference parameters in C++ are passed either through pointers or a reference operator, &. In C#, reference parameters are less error prone. Reference parameters are also called In-Out parameters because you pass a reference address of the location, so you pass an input value and get an output value from that function.

You cannot pass an uninitialized reference parameter into a function. C# uses a keyword ref for the reference parameters. You also have to use keyword ref with an argument while passing it to a function-demanding reference parameter.

Example:

    int a= 5;
    FunctionA(ref a);        // use ref with argument or you will
                             // get a compiler error
    Console.WriteLine(a);    // prints 20

    void FunctionA(ref int Val)
    {
        int x= Val;
        Val = x* 4;
    }
Out parameter

The Out parameter is the parameter that only returns a value from the function. The input value is not required. C# uses the keyword out for the out parameters

Example:

    int Val;
    GetNodeValue(Val);

    bool GetNodeValue(out int Val)
    {
        Val = value;
        return true;
    }
Variable number of parameters and arrays

Arrays in C# are passed through a keyword params. An array-type parameter should always be the right-most argument of the function. Only one parameter can be of the array type. You can pass any number of elements as an argument of type of that array. You can better understand it from the following example.

Example:

    void Func(params int[] array)
    {
        Console.WriteLine("number of elements {0}",
                           array.Length);
    }

    Func();                      // prints 0
    Func(5);                     // prints 1
    Func(7,9);                   // prints 2
    Func(new int[] {3,8,10});    // prints 3
    int[] array = new int[8] {1,3,4,5,5,6,7,5};
    Func(array);                 // prints 8

Operators and Expressions

Operators are exactly the same as om C++ and thus the expression, also. However, some new and useful operators have been added. Some of them are discussed here.

is operator

The is operator is used to check whether the operand types are equal or convertable. The is operator is particularly useful in the polymorphism scenarios. The is operator takes two operands and the result is a boolean. See the example:

void function(object param)
{
    if(param is ClassA)
        //do something
    else if(param is MyStruct)
        //do something
    }
}
as operator

The as operator checks whether the type of the operands are convertable or equal (as is done by is operator) and if it is, the result is a converted or boxed object (if the operand can be boxed into the target type, see boxing/unboxing). If the objects are not convertable or boxable, the return is a null. Have a look at the example below to better understand the concept.

Shape shp = new Shape();
Vehicle veh = shp as Vehicle;   // result is null, types are not
                                // convertable

Circle cir = new Circle();
Shape shp = cir;
Circle cir2 = shp as Circle;    //will be converted

object[] objects = new object[2];
objects[0] = "Aisha";
object[1] = new Shape();

string str;
for(int i=0; i&< objects.Length; i++)
{
    str = objects[i] as string;
    if(str == null)
        Console.WriteLine("can not be converted");
    else
        Console.WriteLine("{0}",str);
}

Output:
Aisha
can not be converted

Statements

Statements in C# are just like in C++ except some additions of new statements and modifications in some statements.

The following are new statements:

foreach

For iteration of collections, such as arrays, and so forth.

Example:

    foreach (string s in array)
        Console.WriteLine(s);
lock

Used in threads for locking a block of code, making it a critical section.

checked/unchecked

The statements are for overflow checking in numeric operations.

Example:

int x = Int32.MaxValue; x++;    // Overflow checked
{
x++;                            // Exception
}
unchecked
{
x++;                            // Overflow}
}

The following statements are modified:

Switch

The Switch statement is modified in C#.

  1. Now, after executing a case statement, program flow cannot jump to the next case, which was previously allowed in C++.
    Example:
    int var = 100;
    switch (var)
    {
        case 100: Console.WriteLine("<Value is 100>");
            // No break here
        case 200: Console.WriteLine("<Value is 200>"); break;
    }
    Output in C++:
        <Value is 100><Value is 200>
    

    In C#, you get a compile time error:

    error CS0163: Control cannot fall through from one case label
    ('case 100:') to another
    
  2. However, you can do this similarly to the way you do it in C++:
    switch (var)
    {
        case 100:
        case 200: Console.WriteLine("100 or 200<VALUE is 200>");
                  break;
    }
    
  3. You also can use constant variables for case values:

    Example:

    const string WeekEnd  = "Sunday";
    const string WeekDay1 = "Monday";
    
    ....
    
    string WeekDay = Console.ReadLine();
    switch (WeekDay )
    {
    case WeekEnd: Console.WriteLine("It's weekend!!"); break;
    case WeekDay1: Console.WriteLine("It's Monday"); break;
    
    }
    

Delegates

Delegates let us store function references into a variable. In C++, this is like using and storing a function pointer for which we usually use typedef.

Delegates are declared using a keyword delegate. Have a look at this example, and you will understand what delegates are:

Example:

delegate int Operation(int val1, int val2);
public int Add(int val1, int val2)
{
    return val1 + val2;
}
public int Subtract (int val1, int val2)
{
    return val1- val2;
}

public void Perform()
{
    Operation Oper;
    Console.WriteLine("Enter + or - ");
    string optor = Console.ReadLine();
    Console.WriteLine("Enter 2 operands");

    string opnd1 = Console.ReadLine();
    string opnd2 = Console.ReadLine();

    int val1 = Convert.ToInt32 (opnd1);
    int val2 = Convert.ToInt32 (opnd2);

    if (optor == "+")
        Oper = new Operation(Add);
    else
        Oper = new Operation(Subtract);

    Console.WriteLine(" Result = {0}", Oper(val1, val2));
}

Inheritance and Polymorphism

Only single inheritance is allowed in C#. Mutiple inheritance can be acheived by using interfaces.

Example:

class Parent{
}

class Child : Parent
Virtual Functions

Virtual functions implement the concept of polymorphism are the same as in C#, except that you use the override keyword with the virtual function implementaion in the child class. The parent class uses the same virtual keyword. Every class that overrides the virtual method will use the override keyword.

class Shape
{
    public virtual void Draw()
    {
        Console.WriteLine("Shape.Draw")    ;
    }
}

class Rectangle : Shape

{
    public override void Draw()
    {
        Console.WriteLine("Rectangle.Draw");
    }
}

class Square : Rectangle
{
    public override void Draw()
    {
        Console.WriteLine("Square.Draw");
    }
}
class MainClass
{
    static void Main(string[] args)
    {
        Shape[] shp = new Shape[3];
        Rectangle rect = new Rectangle();

        shp[0] = new Shape();
        shp[1] = rect;
        shp[2] = new Square();

        shp[0].Draw();
        shp[1].Draw();
        shp[2].Draw();
    }
}
Output:
Shape.Draw
Rectangle.Draw
Square.Draw
Hiding parent functions using "new"

You can define in a child class a new version of a function, hiding the one which is in base class. A new keyword is used to define a new version. Consider the example below, which is a modified version of the above example and note the output this time, when I replace the override keyword with a new keyword in the Rectangle class.

class Shape
{
    public virtual void Draw()
    {
        Console.WriteLine("Shape.Draw")    ;
    }
}

class Rectangle : Shape
{
    public new void Draw()
    {
        Console.WriteLine("Rectangle.Draw");
    }
}
class Square : Rectangle
{
    //wouldn't let you override it here
    public new void Draw()
    {
        Console.WriteLine("Square.Draw");
    }
}
class MainClass
{
    static void Main(string[] args)
    {
        Console.WriteLine("Using Polymorphism:");
        Shape[] shp = new Shape[3];
        Rectangle rect = new Rectangle();

        shp[0] = new Shape();
        shp[1] = rect;
        shp[2] = new Square();

        shp[0].Draw();
        shp[1].Draw();
        shp[2].Draw();

        Console.WriteLine("Using without Polymorphism:");
        rect.Draw();
        Square sqr = new Square();
        sqr.Draw();
    }
}

Output:
Using Polymorphism
Shape.Draw
Shape.Draw
Shape.Draw
Using without Polymorphism:
Rectangle.Draw
Square.Draw

The polymorphism doesn't take the Rectangle class's Draw method as a polymorphic form of the Shape's Draw method. Instead, it considers it a different method. So, to avoid the naming conflict between parent and child, we have used the new modifier.

Note: You cannot use the two version of a method in the same class, one with new modifier and other with override or virtual. As in the above example, I cannot add another method named Draw in the Rectangle class which is a virtual or override method. Also, in the Square class, I can't override the virtual Draw method of the Shape class.
Calling base class members

If the child class has the data members with same name as that of base class, to avoid naming conflicts, base class data members and functions are accessed using a keyword base. See in the examples how the base class constructors are called and how the data members are used.

public Child(int val) :base(val)
{
    myVar = 5;
    base.myVar;
}

OR

public Child(int val)
{
    base(val);
    myVar = 5 ;
    base.myVar;
}

Future Additions:

This article is just a quick overwiew of the C# language so that you can just become familiar with the langauge features. Although I have tried to discuss almost all the major concepts in C# in a brief and comprehensive way with code examples, I think there is lot much to be added and discussed.

In the future, I would like to add more commands and concepts not yet discussed including events and so forth. I would also like to write about Windows programming using C# for beginners.

References

  • our most commonly known MSDN
  • Inside C# by Tom Archer
  • A Programmer's Introduction to C# by Eric Gunnerson
  • Beginning C# by Karli Watson
  • Programming C# (O'Reilly)

About the Author

Aisha is a Master of Science in Computer Science from Quaid-i-Azam Univeristy. She has worked in VC++ 6, MFC, ATL, COM/DCOM, ActiveX, C++, SQL, and so forth. These days she is working on .NET framework and C#. Inspired with nature, she loves to seek knowledge. She is also fond of travelling. She keeps a free source code and articles Web site at http://aishai.netfirms.com.

原文: http://www.codeguru.com/Csharp/Csharp/cs_syntax/article.php/c5837/

Windows QuickMenu 小Y快速工具栏 V2.0 摘要:YQuickMenu是一款C++开发的快捷菜单工具,旨在替代Windows开始菜单管理常用软件。它支持H5自定义界面,体积小巧性能优异,提供分类管理、皮肤设置等功能。用户只需解压即可使用,建议将主程序固定在任务栏。该工具为开发者个人需求的产物,上一个C#版本因性能问题被重构,现开源提供下载(https://gitee.com/yayr/zhida_soft/raw/master/YQuickBarApp.7z),欢迎用户反馈需求。(149字) 阅读详情

相关推荐

llama.cpp部署大模型

llama.cpp如何部署大模型

Eddy的博客 976

C#速成之一(Quick C#)

绪论   C#是这样的一种语言,具有C++的特点,象Java一样的编程风格, 并且象Basic一样的快速开发模型。如果你已经知道了C++,本文会在不到一个小时的时间内让你迅速掌握C#的语法。熟悉Java的括会更好,因为Java的程序结构、打包(Packages)和垃圾收集的概念有助于你更快的了解C#。因此在讨论C#的构造时,我会假定你了解C++。   本文会讨论C#语言的构造与特点,同时会采取...

weixin_34413103的博客 262

深度学习|卷积神经网络

介绍卷积神经网络基本理论,包括卷积层、池化层和全连接层,并阐述LeNet卷积神经网络的构建过程。

weixin_58243219的博客 5722

C# 基于分治法的快速排序算法(Quick Sort)

快速排序是一种基于分治思想的高效排序算法,其核心是通过选取枢轴元素将数组划分为两个子数组,然后递归排序。算法包含三个关键步骤:选择枢轴(可随机选取或取中位数)、分区(将小于枢轴的元素移到左侧)和递归处理子数组。采用Lomuto分区法时,通过交换元素实现分区,时间复杂度平均为O(nlogn),最坏情况下为O(n²)。快速排序适合大数据集,具有缓存友好、尾递归优化等优点,但不稳定且小数据集效率较低。应用场景包括数据库排序、算法预处理和快速选择等。不同语言实现可参考文末链接。

csdn_aspnet的专栏,请点击博客主页右上角三个点中的私信联系 367

flowable工作流源码解析-DB访问

Flowable用了mybatis组件,又实现了自己的command和interceptor机制。具体是怎么实现的呢? 我们以Deployment操作为例,来看看它的调用链 调用端是Service接口, 它委托自己的commandExecutor去执行具体的Command. Command最终会调用到EntityManager,然后委托给ibatis的sqlsession来完成操作。 其中CommandExcutor调用command的地方有些复杂,我们展开看: CommandExecutor会维护一系

coobee的博客 2484

概率论 知识图谱 + 实战案例解析

本文通过构建概率论知识图谱,系统梳理了从随机试验、概率、条件概率到随机变量与分布的核心概念及其内在联系。结合朴素贝叶斯分类器和蒙特卡洛模拟等实战案例,深入解析了条件概率、独立性及大数定律等理论如何应用于机器学习与实际问题求解,旨在帮助读者建立结构化思维,将理论有效转化为解决实际问题的能力。

weixin_29051193的博客 266

C++ 基于分治法的快速排序算法(Quick Sort)

快速排序是一种高效的分治排序算法,其核心是通过选择枢轴元素将数组分区,使左侧元素小于枢轴、右侧元素大于枢轴,然后递归处理子数组。算法包含三个关键点:枢轴选择(可采用固定位置、随机或中位数策略)、分区操作(常用Lomuto或Hoare方法)和递归终止条件。其平均时间复杂度为O(nlogn),最坏情况下为O(n²)。优势包括内存效率高、适合大数据集,但存在不稳定性和小数据集性能不佳的缺点。该算法广泛应用于排序库、数据库索引等场景,是实践中最高效的通用排序算法之一。

csdn_aspnet的专栏,请点击博客主页右上角三个点中的私信联系 256

思科网络进阶——多生成树协议(MSTP)配置的一课一得

三、实验拓扑1)设计一个网络架构,要有核心层和接入层,都使用思科交换机。2)企业有4个部门,要求这四个部门都可以上网,但分属不同的VLAN中,这样今后可以做其它安全策略以确保网络安全,这些策略如今后学到的访问控制列表ACL。3)网络架构的设计要具有冗余,防止一条线路或一台设备终端导致的业务中断。4)由于硬件冗余而产生的环路要处理好,也就是要在逻辑上(或者说通过配置)防止物理环路的产生。5)不能因为防止物理环路而导致某端口没有流量,这样浪费端口资源及设备间互联的带宽资源。

zhu52010的博客 3398

JavaScript 基于分治法的快速排序算法(Quick Sort)

快速排序是一种高效的分治排序算法,通过选择枢轴元素将数组分区,使较小元素居左、较大元素居右,然后递归处理子数组。算法包含选择枢轴、分区和递归调用三个步骤。枢轴选择方式包括固定位置、随机选取或中位数法。分区算法主要有朴素法、Lomuto法和Hoare法,其中Lomuto法简单易用但效率较低。快速排序平均时间复杂度为O(nlogn),最坏情况为O(n²),空间复杂度取决于递归深度。其优势包括高效处理大数据、缓存友好和尾递归优化,缺点是不稳定且小数据集效率低。广泛应用于数据库排序、算法预处理等领域。

csdn_aspnet的专栏,请点击博客主页右上角三个点中的私信联系 303

UR5双臂Gazebo仿真(Python)

近来在Gazebo上搭了一个ur5双臂仿真平台。 差不多就是以下这样。 使用rostopic list查看一下话题,如下 显然,采用/left_arm_controller/follow_joint_trajectory/goal和/right_arm_controller/follow_joint_trajectory/goal两个话题来控制双臂的运动。 现在的问题是,如何保证双臂运动的一致性,即如何能保证双臂能同时接受到以上两个消息。 思路一:设置/left_arm_controlle

qq_42823342的博客 2233

储能电池管理系统介绍(一)

介绍储能BMS的架构以及各模块功能

manjixingkong1234的专栏 1916

C语言 基于分治法的快速排序算法(Quick Sort)

本文介绍了快速排序算法的原理与实现。快速排序是一种基于分治思想的高效排序算法,通过选择枢轴元素、分区和递归调用来完成排序。文章详细阐述了枢轴选择的三种方法(固定选择、随机选择和中位数选择)以及三种分区算法(朴素分区、Lomuto分区和Hoare分区)。同时分析了算法的时间复杂度(最优O(nlogn),最差O(n²))和空间复杂度,并讨论了快速排序的优缺点及应用场景。最后提供了使用Lomuto分区法的C语言实现代码示例,展示了该算法的具体实现方式。

csdn_aspnet的专栏,请点击博客主页右上角三个点中的私信联系 214

【YOLO26实战全攻略】08——YOLO26模型导出与部署全攻略:从训练权重到生产环境(含5种格式+INT8量化+实战案例)

本文聚焦YOLO26模型从训练权重到生产环境的全流程部署,针对“训练精度高、部署效果差”的行业痛点,详解其无NMS端到端推理、量化友好架构、全格式导出三大核心优势。内容涵盖ONNX、TensorRT、OpenVINO、TFLite、CoreML五种主流格式的导出原理与实操步骤,深入剖析INT8量化、混合量化等边缘优化技术,并通过智慧园区车辆检测虚拟案例,完整演示从模型准备、格式导出、引擎适配到性能验证的全流程。文中提供可直接复制运行的代码、详细执行结果及避坑指南,兼顾新手入门与进阶读者提升,更好的帮助读者。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 500

Python 基于分治法的快速排序算法(Quick Sort)

快速排序是一种基于分治思想的高效排序算法,通过选择枢轴元素将数组分区,递归处理子数组完成排序。文章详细介绍了三种分区方法(朴素、Lomuto、霍尔),重点解析了Lomuto分区算法的实现原理和Python示例代码。该算法平均时间复杂度为O(nlogn),最坏情况下为O(n²),适用于大数据处理但不适合小数据集。文章还分析了快速排序的优缺点(如缓存友好但不稳定)及其应用场景(数据库排序、快速选择等),并提供了多种语言实现的参考链接。

csdn_aspnet的专栏,请点击博客主页右上角三个点中的私信联系 214

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Java 基于分治法的快速排序算法(Quick Sort)

快速排序是一种高效的分治排序算法,通过选取枢轴元素将数组分区,使较小元素位于左侧,较大元素位于右侧,然后递归处理子数组。算法包含选择枢轴、分区和递归三个步骤,最坏时间复杂度为O(n²),平均为O(nlogn)。枢轴选择方法包括固定位置、随机选取或中位数法,分区算法则有朴素法、Lomuto法和霍尔法。快速排序优势在于处理大数据集高效、内存占用少,但不稳定且小数据集表现不佳。适用于库函数排序、数据库记录排序等场景。

csdn_aspnet的专栏,请点击博客主页右上角三个点中的私信联系 218

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

精品收藏---集合之Array.Reverse 方法的技巧

语法  public static void Reverse( Array array ) 参数 array类型:System.Array 要反转的一维 Array。 示例 下面的代码示例说明如何反转 Array 中的值的排序。 using System; public class

續寫經典 1031

Unity全局资源检索目录配置:从搜索原理到工程实践

在游戏开发中,资源管理是影响团队协作效率的核心环节。Unity引擎的搜索机制基于资产的文件名、类型和标签进行过滤,但其默认的全库扫描模式在项目规模膨胀时,往往导致搜索结果冗余、定位低效。理解其底层原理,特别是Quick Search包的可扩展Provider模型,是进行深度定制的关键。通过编写编辑器脚本,开发者可以创建自定义的Search Provider,将搜索范围限定在预设的“热点目录”,如核心脚本、美术资源或配置文件夹,从而实现精准、快速的资源定位。这种工程化实践不仅提升了开发者的日常工作效率,更在大

weixin_33743661的博客 329

初识QuickGraph

初识QuickGraph 在Gentle.NET的引用中看到了这个东东,google查了一下,有关内容如下: QuickGraph: A 100% C# graph library with Graphviz Support.---不错,不是很懂,因为我的数学不好! http://www.codeproject.com/cs/...

weixin_30753873的博客 155

Unity编辑器扩展开发:快速场景切换工具的实现与优化

在Unity3D开发中,编辑器扩展是提升工作效率的关键技术。通过自定义EditorWindow,开发者可以创建专属工具来优化工作流程。其原理是利用Unity的编辑器API(如AssetDatabase、EditorGUILayout)构建可视化界面,实现对项目资产的快速访问与操作。这种技术的核心价值在于将高频操作路径化繁为简,显著减少开发中的重复性劳动,保护开发者的“心流”状态。典型的应用场景包括资源管理、批量处理、快速测试等。本文以【快速场景切换】工具为例,深入讲解如何从需求分析、技术选型到完整实现一个高

weixin_30314793的博客 413

5分钟掌握Flow Launcher:Windows效率启动器终极指南

还在为寻找文件、启动应用而频繁切换鼠标吗?Flow Launcher是一款专为Windows用户设计的快速文件搜索与应用启动工具,通过键盘快捷键和智能搜索彻底改变你的工作方式。这款开源免费的效率神器不仅能快速启动应用程序,还能搜索文件、执行系统命令,甚至通过插件扩展无限功能,让你的Windows操作体验提升到全新高度。 ## 为什么你需要一个专业的启动器? 在数字时代,效率就是生产力。想象一下

gitblog_00845的博客 861

Flow Launcher终极指南:用开源启动器重塑你的Windows工作流

还在为Windows系统的繁琐操作而烦恼吗?每天重复点击开始菜单、在层层文件夹中寻找文件、手动调整系统设置——这些低效操作正在悄悄消耗你的宝贵时间。Flow Launcher作为一款完全免费的开源高效启动器,将彻底改变你的Windows使用习惯,实现真正的"指尖掌控全局"。这款工具不仅支持快速应用启动和文件搜索,还拥有强大的插件生态,能够将你的工作效率提升数倍。 ## 🚀 五分钟极速上手:从安

gitblog_00119的博客 803

Flow Launcher:如何用这款开源工具彻底改变你的Windows工作效率

你是否厌倦了在Windows中反复点击开始菜单、在层层文件夹中寻找文件、手动调整系统设置的低效操作?Flow Launcher作为一款完全免费的开源高效启动器,将彻底改变你的Windows使用习惯,实现真正的"指尖掌控全局"。这款工具不仅支持快速应用启动和文件搜索,还拥有强大的插件生态,能够将你的工作效率提升数倍。 ## 为什么选择Flow Launcher?三大核心优势解析 ### 极速启动

gitblog_01075的博客 869

高效学习算法:技术人快速掌握新技能的实战框架

在技术快速迭代的今天,高效学习能力成为开发者的核心竞争力。学习算法作为认知科学的工程实践,通过优化注意力管理、知识获取和记忆强化等环节,能显著提升学习效率。其核心原理在于将学习过程拆解为可量化的步骤,结合艾宾浩斯遗忘曲线等认知规律设计训练方案。这种方法特别适合需要快速掌握新技术栈的程序员,例如通过3F法则(Fast、Focused、Feedback)快速切入新技术领域,或利用Anki闪卡系统将知识留存率从28%提升至90%。在Web前端、Python等热门技术领域,已有大量开发者通过这套系统在3个月内达到接

weixin_30487201的博客 308
上一篇: [转贴]一个真实的故事,使我这个曾经邪恶的心为之颤栗-
下一篇: 美国让人喷饭的法律
Vigorcsdn
博客等级 码龄23年 0粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值