转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
按照字典顺序比较字符串当str1 > str2时,返回1当str1 = str2时,返回0当str1 < str2时,返回-1ignoreCase:true 忽略大小写
string str=string.Concat("c","#"); //str="c#";
string str=String.Format("今年是{0}年","2022");//str="今年是2022年";
string str2="";bool b2=string.IsNullOrEmpty(str2);//b2=true;string str3=null;bool b3=string.IsNullOrEmpty(str3);//b3=true;
string strs=string.Join(",",string[]{"w","e","r","t"});//strs="w,e,r,t";
string update_invoice = FINVO System.CollectionICENUMBER + "," + invoiceNumber; // 追加发票号string[] oldInvoiceList = update_invoice.Split(new Char[] { ',' });string update_invoice_str = string.Join(",", oldInvoiceList.Distinct().ToArray());
string str="我爱编程";bool b=str.Contains("程");//b=true;
string str="我好喜欢你";bool b1=str.StartsWith("好");//b1=false;bool b2-str.EndsWith("你");//b2=true;
string str1="asd";string str2="ert";bool b = str1.Equals(str2); //b=false;bool <strName>.Equals(string str, StringComparison.OrdinalIgnoreCase) //表示不区分大小写
string str ="今天的雨很大,天很冷";int i=str.IndexOf("很"); //i=4;int i=str.LastIndexOf("很");//j=8;int m=str.IndexOf("小");//m=-1;
string str="好困呀";string s=str.Replace("困","精神");//s="好精神呀";
string str="夜深了";string s=str.Insert(1,"已经");// s="夜已经深了"
string str="夜已经深了";string s=str.Remove(1,2);//s="夜深了";
string str="我,真的、好困;呀";string[] s=str.Split(new char(){',','、',';'});//s=string[]{"我","真的","好困","呀"};
string str="还在下雨";string s=str.Substring(2,2);//s="下雨";
string str="雨已经小了";char[] s=str.ToCharArray();//s=char[]{'雨',"已","经","小","了"};
string str=" aa ";string s=str.Trim();//s="aa";
string s="RaSer";string s1=s.ToUpper();//s1="RASER";string s2=s.ToLower();//s2="raser";
using System.Collections.Generic;List<string> list = new List<string>();list.Add("a");
using System;using System.Collections.Generic;using System.Linq;List<string> list1 = new List<string>() {"123","456","789","789" };// ["123","456","789","789"]List<string> newList = list1.Distinct().ToList(); //["123","456","789"]
using System;using System.Collections.Generic;using System.Linq;List<string> list1 = new List<string>() {"123","456","789","789" };// ["123","456","789","789"]if(list1.Contains("123")){ Console.WriteLine(true);}else{ Console.WriteLine(false);}
using System;using System.Collections.Generic;using System.Linq;List<int> sqlList = new List<int>();for(int i=0;i<100;i++){ sqlList.Add(i);}Console.WriteLine(sqlList.ToString());List<List<int>> sql_batch = sqlList.Select((x, i) => new { Index = i, Value = x }) .GroupBy(x => x.Index / 5) //分成5组 .Select(x => x.Select(v => v.Value).ToList()) .ToList();Console.WriteLine(sql_batch.ToString());
using System; using System.Collections;Hashtable table = new Hashtable();//添加的是键值对 table.Add("name", "zhangsan"); table.Add("age", 10); table.Add("gender", "male");
using System;using System.Collections;Hashtable table = new Hashtable();table.Add("age", 10);//通过Key来删除一个键值对 table.Remove("age");
using System;using System.Collections;Hashtable table = new Hashtable();table.Add("age", 10);//通过Key来修改元素table["age"] = 30;
using System;using System.Collections;Hashtable table = new Hashtable();//添加的是键值对 table.Add("name", "zhangsan");table.Add("age", 10);table.Add("gender", "male");ICollection keys = table.Keys;//遍历刚刚获取到的所有的Keyforeach (object key in keys){ //通过Key来获取Value Console.WriteLine($"{key}={table[key]}");}
using System; using System.Collections;Hashtable table = new Hashtable();//添加的是键值对 table.Add("name", "zhangsan"); table.Add("age", 10); //Hashtable中存储的元素类型是DictionaryEntryforeach (DictionaryEntry entry in table){ //获取一个键值对中的键 object key = entry.Key; //获取一个键值对中的值 object value = entry.Value; Console.WriteLine($"{key}={value}");}
using System;using System.Collections;Hashtable table = new Hashtable();int Count = table.Count;
using System; using System.Collections;Hashtable table = new Hashtable();table.Clear();
using System; using System.Collections;Hashtable table = new Hashtable();//添加的是键值对 table.Add("name", "zhangsan"); table.Add("age", 10); bool result = table.Contains("age");
using System.Collections.Generic;Dictionary<int,string > dict = new Dictionary<int,string>();dict.Add(1,"111");dict.Add(2,"222");
using System.Collections.Generic;Dictionary< string , int > d = new Dictionary< string , int >();d.Add( "C#" , 2);d.Add( "VB" , 1);d.Add( "C" , 0);d.Add( "C++" , -1);//删除键为“C”的元素d.Remove( "C" );//删除键为“VB”的元素d.Remove( "VB" );
using Newtonsoft.Json;using System.Collections.Generic;Dictionary<string, int> dic = new Dictionary<string, int>() { {"张三",1}, {"李四",2},};string result = JsonConvert.SerializeObject(dic);Console.WriteLine(result); //{"张三":1,"李四":2}
using Newtonsoft.Json;using System.Collections.Generic;result = "{\"张三\":1,\"李四\":2}";Dictionary<string, int> dic2 = JsonConvert.DeserializeObject<Dictionary<string, int>>(result);foreach (var item in dic2){ Console.WriteLine($"{item.Key}---->{item.Value}");}
using System.Collections.Generic;Dictionary<int,string > dict = new Dictionary<int,string>();if (dict.ContainsKey(<key>)) { Console.WriteLine(dict[<key>]); }
using System.Collections.Generic;Dictionary<int,string > dict = new Dictionary<int,string>();foreach (var item in dict.Keys){ Console.WriteLine( "Key:{0}" , item);}
using System.Collections.Generic;Dictionary<int,string > dict = new Dictionary<int,string>();foreach (var item in dict.Values){ Console.WriteLine( "value:{0}" , item);}
using System.Collections.Generic;Dictionary<int,string > dict = new Dictionary<int,string>();foreach (var item in dict){ Console.WriteLine( "key:{0} value:{1}" , item.Key, item.Value);}
using System; using System.Collections.Generic;HashSet<string> hashSet = new HashSet<string>();hashSet.Add("A");hashSet.Add("B");hashSet.Add("C");hashSet.Add("D");// A B C D
hashSet.Contains("D")
hashSet.Remove(item);
hashSet.Clear()
HashSet<string> setA = new HashSet<string>() { "A", "B", "C", "D" };HashSet<string> setB = new HashSet<string>() { "A", "B", "C", "X" };HashSet<string> setC = new HashSet<string>() { "A", "B", "C", "D", "E" };if (setA.IsProperSubsetOf(setC)) //是子集输出1,不是输出0 Console.WriteLine("setC contains all elements of setA.");if (!setA.IsProperSubsetOf(setB)) Console.WriteLine("setB does not contains all elements of setA.");
using System; using System.Collections.Generic;HashSet<string> setA = new HashSet<string>() { "A", "B", "C", "D", "E" };HashSet<string> setB = new HashSet<string>() { "A", "B", "C", "X", "Y" };setA.UnionWith(setB);foreach(string str in setA){ Console.WriteLine(str);}//最终setA的输出结果是 A B C D E X Y
using System; using System.Collections.Generic;HashSet<string> setA = new HashSet<string>() { "A", "B", "C", "D", "E" };HashSet<string> setB = new HashSet<string>() { "A", "B", "C", "X", "Y" };setA.IntersectWith(setB);// A B C
using System;using System.Collections.Generic;HashSet<string> setA = new HashSet<string>() { "A", "B", "C", "D", "E" };HashSet<string> setB = new HashSet<string>() { "A", "B", "C", "X", "Y" };setA.ExceptWith(setB);// D E
HashSet<string> setA = new HashSet<string>() { "A", "B", "C", "D", "E" };HashSet<string> setB = new HashSet<string>() { "A", "X", "C", "Y" };setA.SymmetricExceptWith(setB);foreach (string str in setA){ Console.WriteLine(str);}//对于这个示例,最终输出结果是BDEXY
using System;using System.Collections.Generic;SortedSet<string> set1 = new SortedSet<string>();set1.Add("CD");set1.Add("CD");set1.Add("CD");set1.Add("CD");Console.WriteLine("Elements in SortedSet1...");foreach (string res in set1) { Console.WriteLine(res);}
using Kingdee.BOS.JSON;JSONObject jsonObject = new JSONObject();jsonObject.Put("userName", dynamicObjectCollection[0]["USERNAME"]);jsonObject.Put("reason", backMsg);jsonObject.Put("bbcOrderNum",billNo);
using Newtonsoft.Json;using Newtonsoft.Json.Linq;JObject jObject = new JObject();jObject["recMobile"] = Convert.ToString(dynamicObject["FReceiverPhone"]);jObject["recTel"] = Convert.ToString(dynamicObject["FReceiverTel"]);
JObject obj = new JObject();obj.Add("name", "张三");obj.Add("birthday", DateTime.Now); //合并其他对象到当前对象的属性obj.Add("content", JToken.FromObject(new{ code = "zhangsan"}));//返回{ "name":"张三", "birthday","2022-05-04", "content":{ "code":"zhangsan" }}
//合并其他JObject obj = new JObject();obj.Add("name", "张三");obj.Add("birthday", DateTime.Now);JObject obj2 = JObject.FromObject(new{ code = "lisi"});obj.Merge(obj2);//返回{ "name":"张三", "birthday","2022-05-04", "code ":"lisi"}
using Newtonsoft.Json;using Newtonsoft.Json.Linq;string jsonText = @"{ "input": { 'size': 193156, 'type': 'image/png'}";JObject jobject = (JObject)JsonConvert.DeserializeObject(jsonText);decimal input_size = Convert.ToDecimal(jobject["input"]["size"]);//193156, 输入图片大小string input_type = jobject["input"]["type"].ToString();// "image/png",输入图片类型
DateTime time= Convert.ToDateTime("2022-04-28 00:00:00");Console.WriteLine(time);
DateTime dt_now = DateTime.Now;string time=dt_now.ToString("yyyy-MM-dd hh:mm:ss");Console.WriteLine(time);
string time = Convert.ToDateTime("2019-08-28 00:00:00").ToString("yyMMdd");Console.WriteLine(time);
//threadMainConsole.WriteLine("Main方法开始执行...");Thread threadA = new Thread(Execute);threadA.Start();Thread threadB = new Thread(test);threadB.Start();Console.WriteLine("Main方法执行结束...");//threadBprivate void test() { while (true) { Console.WriteLine($"test:{DateTime.Now.Ticks}"); }}//threadAprivate void Execute() { Console.WriteLine("开始下载,此协程的Id是:" + Thread.CurrentThread.ManagedThreadId); int bill_count = billNoList.Count; Thread.Sleep(5000 * bill_count); foreach (string billNo in billNoList) { getIvnumber(billNo); } Console.WriteLine("下载完成");}
//定义一个类,用于存放线程需要的数据和线程启动的方法public class MyThread{ private string data;//线程数据 public MyThread(string data) { this.data = data; } //线程启动方法 public void ThreadMain() { Console.WriteLine("Running in a thread, data: {0}", data); }}static void Main(){ MyThread obj = new MyThread("info");//创建实例信息 Thread t3 = new Thread(obj.ThreadMain);//启动实例方法 t3.Start();}
//定义一个数据类型,传递给线程public struct Data{ public string Message;}//创建一个方法,将方法给线程的ParameterizedThreadStart委托static void ThreadMainWithParameters(object obj){ Data d = (Data)obj; Console.WriteLine("Running in a thread, received {0}", d.Message);}static void Main(){ Data d = new Data { Message = "Info" };//创建一个数据实例 Thread t2 = new Thread(ThreadMainWithParameters);//创建线程 t2.Start(d);//启动线程,并传递参数}
//前台线程//创建线程方法,以在主线程中调用static void ThreadMain(){ Console.WriteLine("Thread {0} started", Thread.CurrentThread.Name); Thread.Sleep(3000); Console.WriteLine("Thread {0} completed", Thread.CurrentThread.Name);}static void Main(){ Thread t1 = new Thread(ThreadMain); t1.Name = "MyNewThread"; t1.Start(); Thread.Sleep(100); Console.WriteLine("Main thread ending now..."); /*******************输出******************** * Thread MyNewThread started * Main thread ending now... * Thread MyNewThread completed * *****************************************/}
//后台线程static void Main(){ Thread t1 = new Thread(ThreadMain); t1.Name = "MyNewThread"; t1.IsBackground = true; t1.Start(); Thread.Sleep(100); Console.WriteLine("Main thread ending now..."); /*******************输出******************** * Thread MyNewThread started * Main thread ending now... * *****************************************/}
前台线程:主线程默认启动方式为前台线程,主线程结束后,前台线程仍可以活动。后台线程:如果在线程启动前,将线程的IsBackground属性设置为true,主线程结束时,会终止新线程的执行(不论是否完成任务)。
using System;Random r = new Random();Console.WriteLine(r.Next(1,5));
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!
转载请注明来源 https://www.cnblogs.com/brucejiao/p/16188865.html 谢谢!