学习C#基础必看案例



 点击   更多基础资源



            //Random随机数
            Random r = new Random();
            while (true)
            {
                int i = r.Next(1, 7);
                Console.WriteLine(i);
                Console.ReadKey();
                
            }






            //指定分隔符数组,返回不带空格符的字符串
            string str = "my         name                   is lei";
            char[] a = { ' ' };
            string[] b = str.Split(a,StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < b.Length; i++)
            {
                Console.WriteLine(b[i]);
            }
            Console.ReadKey();






            //倒序输出
            Console.WriteLine("请输入字符串");
            string a = Console.ReadLine();
            string[] d = a.Split(' ');
            for (int i = d.Length - 1; i >= 0;i-- )
            {
                Console.Write(d[i]+" ");
            }


            Console.ReadKey();




           //忽略大小写
            string a = "a";
            string b = "A";
            if (a.Equals(b,StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("一样的");
            }
            else { Console.WriteLine("不一样"); }
            
            Console.ReadKey();




            //字符替换
            string a = "2008-11-12";
            string[] b = a.Split('-');
            Console.WriteLine("{0}年{1}月{2}日", b);
            Console.ReadKey();




            //九九乘法表
            for (int i = 1; i <= 9;i++ )
            { 
                
                for (int j = 1; j <= i;j++ )
                {
                    
                    Console.Write("{0}X{1}={2:00}   ",i,j,i*j);
                }
                Console.WriteLine();
            }
            Console.ReadKey();




            //判断字符串内是否有指定的子字符串
            string[] strc = { "xxoo", "TMD", "和谐" };
            string a = Console.ReadLine();
            int i;
            for (i = 0; i < a.Length; i++)
            {
                if (a.Contains(strc[i]))
                {
                    break;
                }
            }
            if (i < a.Length)
            {
                Console.WriteLine("有非法字符");
            }
            else
            {
                Console.WriteLine("合法");
            }




            //水仙花规则
            //int i = 1 * 1 * 1 + 5 * 5 * 5+3 * 3 * 3;
            
            //求100_999的水仙花数
            for (int i = 100; i <= 999;i++ )
            { 
                //把个 十 百  分离出来
                int ge=i%10;
                int shi=i/10%10;
                int bai=i/100;
                //按照水仙花数规则判断
                if(i==ge*ge*ge+shi*shi*shi+bai*bai*bai )
                {
                    Console.WriteLine(i);
                }
            }
            Console.ReadKey();






           // 求1_100直接的偶数和
            int sum = 0;
            for (int i = 1; i <= 100;i++ )
            {
                //如果i能被2整除说明这个数是偶数
                if(i%2==0)
                {
                    sum += i;
                    Console.WriteLine(i);
                }
            }
            Console.WriteLine(sum);
            Console.ReadKey();
        }













           更多.NET全套金典教材:       点击进入
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#学习的101个经典例子,例子个个经典,涵盖C#的方方面面,带有说详尽的注释 Advanced - Multithreading - How-To Async Calls Advanced - Remoting - How-To TCP Remoting Advanced - Serialization - How-To Serializing Objects Advanced .NET Framework (GDI+) - Animation with GDI+ Advanced .NET Framework (GDI+) - Create a Screensaver with GDI+ Advanced .NET Framework (GDI+) - Use GDI+ to manipulate images Advanced .NET Framework (GDI+) - Working with GDI+ Brushes Advanced .NET Framework (GDI+) - Working with GDI+ Text Advanced .NET Framework (Localization) - Work with Resource Files Advanced .NET Framework (Networking) - Use Sockets Advanced .NET Framework (Threading) -- Thread Pooling Advanced .NET Framework (Windows Services) - Create a Windows Service Advanced .NET Framework - Interacting Windows Service Advanced .NET Framework - Make WIn32 API Calls Data Access - Bind Data in a ComboBox Data Access - Build a Master-Detail Windows Form Data Access - Create an Offline Application Data Access - Custom Data Binding Format Handlers Data Access - Data Entry Form Data Access - How-To Create a Database Data Access - N-Tier Data Form and Data Layer Data Access - Read and Write Images from a Database Data Access - Retreive and Process data with a SQL Data Reader Data Access - Sort and Filter with a DataView Data Access - Use ADO 2.6 Data Access - Use Stored Procedures Data Access - Using Typed Datasets File - How-To File Notifications File - How-To File System Framework - Comparison of DataBinding in Web and Windows Forms Framework - Creating an Enterprise Services Component Framework - How-To Configuration Settings Framework - How-To Environment Settings Framework - How-To MSMQ Framework - How-To Process Viewer Framework - How-To Reflection Framework - How-To Send and Receive Data Framework - How-To Service Manager Framework - How-To Stack Frame Framework - How-To System Events Framework - How-To Work with XML Framework - Key Benefits Framework - Partitioning your application Framework - role based security with Enterprise Services Framework - Scoping, Overloading, Overriding Framework - Understanding the Garbage Collector Framework - Using the COM Port Framework - Using WMI Interop - Automate IE Language - How-To Arrays Language - How-To Build a Custom Collection Class Language - How-To Callbacks Language - How-To DateTime Language - How-To OO Features Language - How-To Strings Language - How-To Try Catch Finally NET Framework - Create and use Trace Listeners NET Framework - How-To Send Mail NET Framework - How-To Use the EventLog NET Framework - How-To Working with GDI+ Pens NET Framework - Read and Write Performance Counters NET Framework - Reading and Writing with a Text File NET Framework - Use Temporary Files NET Framework - Use the Process Class and Shell Functionality NET Framework - Work with Console Applications Security - Create a Login Dialog Box Security - Encrypt and Decrypt Data Security - How-To Role-based Security Security - Use Cryptographic Hash Algorithms VS.NET - Create a VS.NET Add-In Web Development - Data Entry Form Web Development - Exposing a Simple Web Service Web Development - Master-Details Web Form Web Development - Paging through Query Results Web Services - Consume a Web Service WebService - How To Transfer Binary Data Windows Forms - How-To Data Binding with Navigation Windows Forms - How-To System Tray Icon Windows Forms - How-To Validating Textboxes Windows Forms - Associating Help with an Application Windows Forms - Create an Explorer Style Application Windows Forms - How-To Automate Office Windows Forms - How-To Common Dialogs Windows Forms - How-To Data Grid Formatting Windows Forms - How-To DataGrid Sorting and Filtering Windows Forms - How-To Inherited Windows Forms Windows Forms - How-To ListBox and ComboBox Windows Forms - How-To Menus Windows Forms - How-To Top-Level Forms Windows Forms - How-To Use Drag and Drop Windows Forms - How-To XML Comments Windows Forms - Simple Printing Windows Forms - Use Crystal Reports Windows Forms - Use Format Codes to Format Data in Strings Windows Forms - Use Regular Expressions Windows Forms - Use the Clipboard Windows Forms - XP Theme Support Windows Forms -- Owner Drawn Menus Windows Forms- How-To Custom Exceptions WinForms - Dynamic Control Creation

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值