「C#」ContainsメソッドでListの要素にあるかを返す方法

構文
public bool Contains(
T item
)
C#コード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Collections.Generic;
namespace com.arkgame.ConsoleAppDemo
{
class Program
{
static void Main(string[] args)
{
var cftLst = new List<string>();
cftLst.Add("AA");
cftLst.Add("BB");
cftLst.Add("CC");
cftLst.Add("DD");
cftLst.Add("EE");
string target = "DD";
if (cftLst.Contains("DD"))
{
Console.WriteLine("要素{0}が見つかりました",target);
}
}
}
}
using System; using System.Collections.Generic; namespace com.arkgame.ConsoleAppDemo { class Program { static void Main(string[] args) { var cftLst = new List<string>(); cftLst.Add("AA"); cftLst.Add("BB"); cftLst.Add("CC"); cftLst.Add("DD"); cftLst.Add("EE"); string target = "DD"; if (cftLst.Contains("DD")) { Console.WriteLine("要素{0}が見つかりました",target); } } } }
using System;
using System.Collections.Generic;

namespace com.arkgame.ConsoleAppDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var cftLst = new List<string>();
            cftLst.Add("AA");
            cftLst.Add("BB");
            cftLst.Add("CC");
            cftLst.Add("DD");
            cftLst.Add("EE");
            string target = "DD";

            if (cftLst.Contains("DD"))
            {
                Console.WriteLine("要素{0}が見つかりました",target); 
            }

        }
    }
}

実行結果
要素DDが見つかりました

C#

Posted by arkgame