I’m Coding !(一)

1、冒泡排序:

需要用两个for循环才能遍历所有的数组元素。2个for循环的用处,就是第一个for循环的每一个分别去比较后一个for循环的所有元素。

 public void addsort(int[] array)
        {
            int length = array.Length;
            for (int y = 0; y < length - 1; y++)
            {

            
                for (int i = 0; i < length - 1; i++)
                {
                    if (array[i] > array[i + 1])
                    {

                        int temp = array[i];
                        array[i] = array[i + 1];
                        array[i + 1] = temp;
                    }}}}
              
        static void Main(string[] args)
        {
            int[] array = { 1, 4, 2, 5, 3 };
            abc ssh = new abc();
            ssh.addsort(array);
            foreach (int i in array)
            {
                Console.WriteLine("{0}", i);
            }
            Console.WriteLine();

        }
    }
}

2、 简单的泛型方法:

class bcd
    {
        public static int Skyy<T>(T[] item, T items)    //创建泛型方法
        {
            for (int i = 0; i < item.Length;i++ )
            {
                if (item[i].Equals(items))
                {
                    return i;
                }
            }
            return -1;
        }
    }

------ 

class Class1
    {

 static void Main(String[] args)
        {
            int i = bcd.Skyy<int>(new int[] { 1, 2, 3, 4, 5 }, 3);
            Console.WriteLine("3在数组中的位置" + i.ToString());
        }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
coding in delphi 2015 ,最新英文版。Well, here we are again.This book is to follow my first book, Coding in Delphi. I was humbled and pleased by the reception it received, and so I decided to give book writing another shot. The first book didn’t have many screen shots of forms and such. The focus was on the code. Ultimately, that’s what we developers produce, right? I thought it would be a good idea to write another book of the same ilk because, well, the first one worked out really well and because there was a lot more to write about. However, this one will have a few screen shots in it, as there are some coding principles – parallel programming comes to mind – where a simple console application won’t quite illustrate things well. So this book will have some VCL applications in the demo code. I’ve actually broken down and included an entire chapter on VCL component writing. My friend, Bob Dawson, suggested that it has been quite a while since anyone wrote about components, and I decided he was right. So we’ll get a chapter covering the latest techniques on building the immortal TSmiley. But the focus will remain, as always, on the code. One of the reasons that I’ve written these books is that they force me to learn new things. I’ll be honest: at the start of the first book, I didn’t always know enough to write a complete chapter on the topic at hand (cough, parallel programming, cough, cough). But I used writing about the topic as an opportunity to learn all I could and share it with you. The same is true of this book – I’ve learned a lot in writing it. This seems to work well, as we both end up smarter. I love learning, and I assume you do, too, because you bought this book. They say that you never really know a topic until you have to teach it, and these books are my way of teaching to learn, in addition to giving back to the Delphi community that has given me so much. Another aspect to this book is that it uses a number of open source frameworks to teach the principles

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值