看到一段代码,如下(.net2.0中)
private static string[] autoCompleteWordList = null;
        [WebMethod]
        public String[] GetCompleteList(string prefixText, int count)
        {
            if (autoCompleteWordList == null)
            {
                string[] temp = File.ReadAllLines(Server.MapPath("~/TextFile.txt"));
                Array.Sort(temp, new CaseInsensitiveComparer());
                autoCompleteWordList = temp;
            }            int index = Array.BinarySearch(autoCompleteWordList, prefixText, new CaseInsensitiveComparer());
            if (index < 0)
            {
                index = ~index;
            }            int matchingCount;
            for (matchingCount = 0; matchingCount < count && index + matchingCount < autoCompleteWordList.Length; matchingCount++)
            {
                if (!autoCompleteWordList[index + matchingCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }
            }
            String[] returnValue = new string[matchingCount];
            if (matchingCount > 0)
            {
                Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount);
            }
            return returnValue;
        }
请问
       index = ~index;
  这是什么意思, 我好像都没见过这用法
顺便问一下,Server.MapPath("~/TextFile.txt"));这“~/”的写法,在.net1.1中好像没有
望大虾赐教
           

解决方案 »

  1.   

    Web 应用程序根目录运算符(~),在服务器控件中指定路径时可以使用该运算符。ASP.NET会将~运算符解析为当前应用程序的根目录。可以结合使用~运算符和文件夹来指定基于当前根目录的路径。这种问题你应该去看MSDN...
      

  2.   

    ~表示网站虚拟目录下的文件,例如有个虚拟目录在wwwroot/test/,那么在wwwroot/test/a/b下Server.MapPath("~/TextFile.txt"))表示wwwroot/test/TestFile.txt这个文件。
      

  3.   

    ~ 运算符对操作数执行按位求补操作.Server.MapPath("~/")表示当前应用级程序的目录
      

  4.   


     index   =   ~index; 
    是按位取“非”