Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# contains

作者:幸福的起点   发布日期:2025-04-30   浏览:73

using System;

class Program
{
    static void Main()
    {
        string sentence = "Hello, welcome to the world of C#!";

        // 使用 Contains 方法检查字符串中是否包含指定的子字符串
        bool containsCSharp = sentence.Contains("C#");

        if (containsCSharp)
        {
            Console.WriteLine("The sentence contains 'C#'.");
        }
        else
        {
            Console.WriteLine("The sentence does not contain 'C#'.");
        }
    }
}

解释说明:

  • Contains 是 C# 中 string 类的一个方法,用于检查一个字符串是否包含指定的子字符串。
  • 在这个示例中,我们定义了一个字符串 sentence,然后使用 Contains 方法来检查该字符串是否包含子字符串 "C#"
  • 如果包含,则输出 "The sentence contains 'C#'.";否则,输出 "The sentence does not contain 'C#'."

上一篇:c# hashtable

下一篇:c# tcp

大家都在看

c# 二进制

c# tcp client

c# type.gettype

c# sqlconnection

.net和c#

c#游戏开发

c#网络编程

c# rectangle

c# if else

c#高并发

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站