当前位置: 首页>>代码示例>>C#>>正文


C# SortedList.Clone方法代码示例

本文整理汇总了C#中System.Collections.SortedList.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.Clone方法的具体用法?C# SortedList.Clone怎么用?C# SortedList.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.SortedList的用法示例。


在下文中一共展示了SortedList.Clone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IComparer_Null_Clone

		public void IComparer_Null_Clone ()
		{
			SortedList sl = new SortedList ((IComparer) null);
			sl.Add (new object (), new object ());
			SortedList clone = (SortedList) sl.Clone ();
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:6,代码来源:SortedListTest.cs

示例2: TestClone

		public void TestClone ()
		{
			{
				SortedList sl1 = new SortedList (10);
				for (int i = 0; i <= 50; i++)
					sl1.Add ("kala " + i, i);
				SortedList sl2 = (SortedList) sl1.Clone ();
				for (int i = 0; i <= 50; i++)
					Assert.AreEqual (sl1 ["kala " + i], sl2 ["kala " + i], "#A:" + i);
			}
			{
				char [] d10 = { 'a', 'b' };
				char [] d11 = { 'a', 'c' };
				char [] d12 = { 'b', 'c' };
				//char[][] d1 = {d10, d11, d12};
				SortedList sl1 = new SortedList ();
				sl1.Add ("d1", d10);
				sl1.Add ("d2", d11);
				sl1.Add ("d3", d12);
				SortedList sl2 = (SortedList) sl1.Clone ();
				Assert.AreEqual (sl1 ["d1"], sl2 ["d1"], "#B1");
				Assert.AreEqual (sl1 ["d2"], sl2 ["d2"], "#B2");
				Assert.AreEqual (sl1 ["d3"], sl2 ["d3"], "#B3");
				((char []) sl1 ["d1"]) [0] = 'z';
				Assert.AreEqual (sl1 ["d1"], sl2 ["d1"], "#B4");
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:27,代码来源:SortedListTest.cs

示例3: IComparer_Clone

		public void IComparer_Clone ()
		{
			SortedList sl = new SortedList (new SortedListComparer ());
			sl.Add (new object (), new object ());
			SortedList clone = (SortedList) sl.Clone ();
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:6,代码来源:SortedListTest.cs

示例4: TestCloneBasic

        public void TestCloneBasic()
        {
            SortedList hsh1;
            SortedList hsh2;

            string strKey;
            string strValue;

            // Vanila test case - Clone should exactly replicate a collection to another object reference
            //afterwards these 2 should not hold the same object references
            hsh1 = new SortedList();
            for (int i = 0; i < 10; i++)
            {
                strKey = "Key_" + i;
                strValue = "String_" + i;
                hsh1.Add(strKey, strValue);
            }

            hsh2 = (SortedList)hsh1.Clone();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                Assert.Equal(strValue, (string)hsh2["Key_" + i]);
            }

            //now we remove an object from the original list
            hsh1.Remove("Key_9");
            Assert.Null(hsh1["Key_9"]);

            Assert.Equal("String_9", (string)hsh2["Key_9"]);

            //now we try other test cases
            //are all the 'other' properties of the SortedList the same?
            hsh1 = new SortedList(1000);
            hsh2 = (SortedList)hsh1.Clone();

            Assert.Equal(hsh1.Count, hsh2.Count);
            Assert.Equal(hsh1.IsReadOnly, hsh2.IsReadOnly);
            Assert.Equal(hsh1.IsSynchronized, hsh2.IsSynchronized);

            //Clone is a shallow copy, so the objects of the objets reference should be the same
            hsh1 = new SortedList();
            for (int i = 0; i < 10; i++)
            {
                hsh1.Add(i, new Foo());
            }

            hsh2 = (SortedList)hsh1.Clone();
            for (int i = 0; i < 10; i++)
            {
                strValue = "Hello World";
                Assert.Equal(strValue, ((Foo)hsh2[i]).strValue);
            }

            strValue = "Good Bye";
            ((Foo)hsh1[0]).strValue = strValue;

            Assert.Equal(strValue, ((Foo)hsh1[0]).strValue);

            //da test
            Assert.Equal(strValue, ((Foo)hsh2[0]).strValue);

            //if we change the object, of course, the previous should not happen
            hsh2[0] = new Foo();
            strValue = "Good Bye";
            Assert.Equal(strValue, ((Foo)hsh1[0]).strValue);

            strValue = "Hello World";
            Assert.Equal(strValue, ((Foo)hsh2[0]).strValue);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:70,代码来源:CloneTests.cs

示例5: TestClone

	public void TestClone() {
		{
			SortedList sl1 = new SortedList(10);
			for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
			SortedList sl2 = (SortedList)sl1.Clone();
			for (int i = 0; i <= 50; i++) {
				AssertEquals("sl.Clone: copying failed @"+i, sl1["kala "+i], sl2["kala "+i]);
			}
		}
		{
			char[] d10 = {'a', 'b'};
			char[] d11 = {'a', 'c'};
			char[] d12 = {'b', 'c'};
			//char[][] d1 = {d10, d11, d12};
			SortedList sl1 = new SortedList();
			sl1.Add("d1",d10);
			sl1.Add("d2",d11);
			sl1.Add("d3",d12);
			SortedList sl2 = (SortedList)sl1.Clone();
			AssertEquals("sl.Clone: Array not matching", sl1["d1"], sl2["d1"]);
			AssertEquals("sl.Clone: Array not matching", sl1["d2"], sl2["d2"]);
			AssertEquals("sl.Clone: Array not matching", sl1["d3"], sl2["d3"]);
			
			((char[])sl1["d1"])[0] = 'z';
			AssertEquals("s1.Clone: shallow copy", sl1["d1"], sl2["d1"]);
		}
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:SortedListTest.cs

示例6: simple

	/* C R E A T E  I N T E R P O L A T I O N S */
	/*----------------------------------------------------------------------------
		%%Function: CreateInterpolations
		%%Qualified: bg._bg.CreateInterpolations
		%%Contact: rlittle

		when we calculate weighted averages, we'd like to do it by just walking
		the list of readings and figuring out the weightings based on that list.
		it won't be that simple (since there are times when you weight forward
		and other times you weight backwards (e.g. around meals)), but we don't
		want to be in the business of creating interpolations at the same time.

		to that end, let's create the interpolations now.
	----------------------------------------------------------------------------*/
	SortedList SlbgeCreateInterpolations(SortedList slbge)
	{
		SortedList slbgeStats = (SortedList) slbge.Clone(); // new SortedList();

		int i;

		// note that we check against the real count every time since we are
		// adding items.

		// TAKE CARE not to add items before the current item without carefully
		// accounting for it with i
		i = 0;
		while (i < slbgeStats.Count)
			{
			BGE bge = (BGE)slbgeStats.GetByIndex(i);
			BGE bgePrevReading = BgePrevReading(slbgeStats, i);
			BGE bgePrevEntry = BgePrevEntry(slbgeStats, i);

//			if (bge.Date.Month == 6)
//				Debug.WriteLine(String.Format("Interp {0}", bge.ToString()));

			if (bge.Type == BGE.ReadingType.Control)
				{
				i++;
				continue;
				}

//			if (bge.Date.Month == 6 && bge.Date.Day == 30 && bge.Date.Hour > 22)
//				Debug.WriteLine("here!");

			if (bgePrevEntry.Carbs > 0)
				{
				TimeSpan tsCarb = bge.Date.Subtract(bgePrevEntry.Date);

				// if the reading since the carb were > 1.5 hours, we can 
				// assume we didn't capture the spike.  use a guess of 10 bgc rise
				// for each carb.  we will put this spike at 90 minutes postprandial
				// (this is one of many tunable places)

				if (tsCarb.TotalMinutes > 90)
					{
					// we are now saying that the last reading we have is 90 minutes
					// postprandial (the one we are estimating)

					// calculate an estimate as a 30bgc per carb rise
					int nEst = bgePrevReading.Reading + bgePrevEntry.Carbs * 15;// * 30;
					AddInterpolatedBge(slbgeStats, bgePrevEntry.Date.AddMinutes(90.0), nEst, "PostPrandial");

					// now, do we have to estimate that 4 hours post prandial we go back to 
					// what we were pre-meal?
					if (tsCarb.TotalMinutes > 240)
						{
						// no reading for 4 hours past the meal -- assume we go
						// back to the pre-reading
						AddInterpolatedBge(slbgeStats, bgePrevEntry.Date.AddMinutes(240.0), bgePrevReading.Reading, "PostPostPrandial");
						}

					// now we want to just continue and reevaluate starting from the previous
					// entry (essentially recursing)
					i = slbgeStats.IndexOfKey(bgePrevReading.Key);
					if (i < 0)
						throw(new Exception("bgePrevReading doesn't have a key but it must!"));

					continue;
					}
				}

			// if this entry has a reading, let's decide if we can weight the entire period of time from the last entry
			// to now, or if we need to interpolate some entries.
			if (bge.Reading != 0)
				{
				// if we have a previous reading...
				if (bgePrevReading.Reading != 0)//  && bge.Date < dttmStop)
					{
					TimeSpan ts = bge.Date.Subtract(bgePrevReading.Date);

					// if the current reading is higher than the previous, assume its
					// .75 of the delta, for been that way for 1/2 of the time
					if (bge.Reading > bgePrevReading.Reading && ts.TotalMinutes > 10.0) // bgePrevReading.Reading)
						{
						int nEst = bgePrevReading.Reading + ((bge.Reading - bgePrevReading.Reading)* 1) / 2;
						AddInterpolatedBge(slbgeStats, bgePrevReading.Date.AddMinutes(ts.TotalMinutes * 0.75), nEst, "75% for 0.5");

						// now we want to just continue and reevaluate starting from the previous
						// entry (essentially recursing)
						i = slbgeStats.IndexOfKey(bgePrevReading.Key);
//.........这里部分代码省略.........
开发者ID:rlittletht,项目名称:bg.incomplete,代码行数:101,代码来源:bg.cs

示例7: BulkUpdateBugs

        private BulkUpdateResult BulkUpdateBugs(Bug bugValuesToBeChanged)
        {
            BulkUpdateResult result = new BulkUpdateResult();

            // get the selected bugs
            SortedList bugs = new SortedList(dgvResults.SelectedRows.Count);
            //string result = string.Empty;

            DataGridViewSelectedRowCollection selRows = dgvResults.SelectedRows;

            int countSelectedBugs = 0;

            if (selRows != null)
            {
                countSelectedBugs = selRows.Count;

                for (int i = 0; i < selRows.Count; i++)
                {
                    DataGridViewRow row = selRows[i];

                    int bugID = int.Parse(row.Cells[BUG_ID_COL_NAME].Value.ToString());

                    Bug bug = GetBugFromCache(bugID);

                    if (bug != null)
                    {
                        if (Utils.ValidateBugStateTransition(bug, bugValuesToBeChanged))
                            bugs.Add(bugID, bugID);
                    }
                    else {
                        //MessageBox.Show("Bug(s) details not loaded yet!");
                        result.CountBugs = 0;
                        result.Message = "Bug(s) details not loaded yet!";

                        return result;
                    }
                }
            }

            result.CountBugs = bugs.Count;
            result.BugsList = (SortedList)bugs.Clone();

            if (bugs.Count > 0)
            {

                IBugBSI bugInterface = (IBugBSI)BLControllerFactory.GetRegisteredConcreteFactory(_connectionId);
                string strError = null;

                result.Message = bugInterface.UpdateBugs(bugs, bugValuesToBeChanged, out strError);

                if (!string.IsNullOrEmpty(strError))
                {
                    throw new Exception(strError);
                }
                else {
                    if(countSelectedBugs > bugs.Count){
                        result.Message = "Only bugs that have a valid bug status transition have been updated!" + Environment.NewLine + "Bugs updated: " + result.ListOfBugs;
                    }
                }
            }
            else
            {
                result.Message = Messages.NoBugWithValidStatusTransition;
            }

            #if DEBUG
            (Utils.FormContainer as MainForm).wb.DocumentText = MyZilla.BL.Interfaces.Utils.htmlContents;
            #endif

            return result;
        }
开发者ID:clarencemorse,项目名称:myzilla,代码行数:71,代码来源:UCResults.cs


注:本文中的System.Collections.SortedList.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。