标题:各位DX帮帮忙啊~~新手请指教
取消只看楼主
xia_ning
Rank: 1
等 级:新手上路
帖 子:2
专家分:2
注 册:2010-8-4
结帖率:100%
已结贴  问题点数:20 回复次数:0 
各位DX帮帮忙啊~~新手请指教
小弟最近在学习C#语言 遇到了一个这样的题目 让小弟把"abc hello bcd" 变成"abc landy bcd"结果 运行结果总是不正确
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace practise
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "abc hello bcd";
            char[] chars = str.ToCharArray();
            int index = str.IndexOf("hello");
                Console.WriteLine(index);
                Console.ReadLine();

                if (index != -1)
                {

                    chars[index] = 'l';
                    chars[index++] = 'a';
                    chars[index++] = 'n';
                    chars[index++] = 'd';
                    chars[index++] = 'y';
                    str = new string(chars);
                    Console.WriteLine(str);
                    Console.ReadLine();
                }                                                                  
        }
    }
}}结果为"abc andyo bcd" 小弟 怎么也想不通 还请各位DX帮帮忙啊
搜索更多相关主题的帖子: 指教 
2010-08-04 17:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-314830-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.107195 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved