private IEnumerator StartTransition(int levelId) { yield return(StartCoroutine(unloadList())); GameObject biomeIcon = getMainBiomeIcon(); if (biomeIcon != null) { Vector2 sizeDelta = ((RectTransform)biomeIcon.transform).sizeDelta; GetComponent <CanvasGroup>().alpha = 0; BiomeIconsContent.GetComponent <CanvasGroup>().alpha = 0; MainButtons.GetComponent <CanvasGroup>().alpha = 0; GetComponent <CanvasGroup>().interactable = false; BiomeIconsContent.GetComponent <CanvasGroup>().interactable = false; MainButtons.GetComponent <CanvasGroup>().interactable = false; GameObject biomeIconCopy = Instantiate(IconPrefab, biomeIcon.transform.position, biomeIcon.transform.rotation, MasterManager.instance.masterCanvas.transform); MasterManager.instance.transitionIconObject = biomeIconCopy; biomeIconCopy.GetComponent <TransitionIcon>().setBackground(curBiome); biomeIconCopy.GetComponentInChildren <Text>().text = levelId >= 0 ? "Level " + levelId : "?"; biomeIconCopy.GetComponentInChildren <Shadow>().effectColor = DataTypes.GetAccentColorFrom(curBiome); RectTransform rectTransform = ((RectTransform)biomeIconCopy.transform); rectTransform.sizeDelta = sizeDelta; RectTransform maskTransform = ((RectTransform)biomeIconCopy.transform.GetChild(0).GetChild(0).transform); RectTransform backgroundTransform = ((RectTransform)biomeIconCopy.transform.GetChild(0).GetChild(0).GetChild(0).transform); backgroundTransform.anchorMin = Vector2.one * 0.5f; backgroundTransform.anchorMax = Vector2.one * 0.5f; Sequence expandLevelIcon = DOTween.Sequence(); yield return(expandLevelIcon .Append(backgroundTransform.DOSizeDelta(new Vector2(2149, 3200), 0.5f)) // .Append(rectTransform.DOSizeDelta(new Vector2(2149, 3200), 0.5f)) .Join(rectTransform.DOAnchorPos(Vector2.zero, 0.5f)) .Join(maskTransform.DOSizeDelta(new Vector2(2000, 2000), 0.5f)) .WaitForCompletion()); } MasterPlayerData.instance.setLastLevelPlayed(curBiome, levelId); GenericDictionary level = new GenericDictionary(); level.Add("levelId", (object)levelId); level.Add("biome", (object)curBiome); MasterManager.instance.SwitchSceneTo("Game", level); }
public void GenericDictionaryTest() { var genericDic = new GenericDictionary <string, Book>(); var book = new Book(); genericDic.Add("123", book); }
static void Main(string[] args) { Console.WriteLine("Enter a number :"); string num = Console.ReadLine(); int num1 = int.Parse(num); var number = new Nullable<int>(num1); Console.WriteLine("Has a value ?: "+ number.HasValue); Console.WriteLine("Value : "+ number.GetValueOrDefault()); Console.WriteLine(""); Console.WriteLine("enter a number :"); string index = Console.ReadLine(); Console.WriteLine("enter a Name :"); string name = Console.ReadLine(); var Nlist = new GenericDictionary<string,string>(); Nlist.Add(index, name); var NList2 = new GenList<string,string>(); NList2.Add(index,name); List<string> NewList = new List<string> { index, name, num }; Console.WriteLine(NewList.LongCount()); Console.WriteLine("choose 1, 2 or 3"); int n = int.Parse(Console.ReadLine()); Console.WriteLine(NewList[n-1]); }
static void Main(string[] args) { var book = new Book { Isbn = "1111", Title = "C# Advanced" }; //Classic way var numbers = new List(); numbers.Add(10); var books = new BookList(); books.Add(book); //Generic var numberList = new GenericList <int>(); numberList.Add(10); var bookList = new GenericList <Book>(); bookList.Add(book); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1234", new Book()); }
// public delegate TResult Func<in T1,in T2, out TResult>(T1 arg1,T2 arg2); static void Main(string[] args) { int number1 = 5; // Lamba Func <int, int> squareOfNumber = i => number1 * number1; Console.WriteLine(squareOfNumber); var lambaDemo = new LambaDemo(); var listOFBooks = lambaDemo.GetBooks().Where(x => x.Price < 10).ToList(); Func <int, int, int> add = Sum; Func <int, int, int> minus = Subtract; int result = minus(5, 3); Console.WriteLine(result); var _doorProcessor = new UnlockDoorProcessor(); var _door = new Door(); _door.KeyNumber = "MY121HN"; Func <Door, string> processor1 = _doorProcessor.UnclockDoor; processor1 += OpenDoorWithRemote; var dd = processor1(_door); Console.ReadLine(); var processor = new PhotoProcessor(); var filters = new PhotoFilters(); Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += CustomerFilter; filterHandler += filters.ApplyContrast; filterHandler += filters.Resize; processor.Process("hhh", filterHandler); var nullable = new Nullables <int>(); var genericInitializerObject = new GenericInitializerObject <Student>(); var student = genericInitializerObject.CreateInitializerObjectGeneric(); student.Name = "Sazi"; student.Surname = "Nyathi"; var results = nullable.GetVaueOrDefault(); var number = new GenericList <int>(); number.Add(10); var students = new GenericList <Student>(); students.Add(student); var studentDictinary = new GenericDictionary <int, Student>(); studentDictinary.Add(1, student); }
/// <summary> /// Add a new generic parameter. /// </summary> /// <typeparam name="T">The type of the generic.</typeparam> /// <param name="keyName">The name of the generic.</param> /// <param name="generics">The target GenericDictionary.</param> private void AddKey <T>(string keyName, GenericDictionary generics) { INodeParameter nodeParameter; var typeT = typeof(T); if (typeT == typeof(string)) { nodeParameter = new NodeParameter(); } else if (typeT == typeof(Texture2D)) { nodeParameter = new NodeParameterTexture(); } else if (typeT == typeof(float)) { nodeParameter = new NodeParameterFloat(); } else if (typeT == typeof(int)) { nodeParameter = new NodeParameterInt(); } else if (typeT == typeof(Vector2)) { nodeParameter = new NodeParameterFloat2(); } else if (typeT == typeof(Vector3)) { nodeParameter = new NodeParameterFloat3(); } else if (typeT == typeof(Vector4)) { nodeParameter = new NodeParameterFloat4(); } else if (typeT == typeof(SamplerState)) { nodeParameter = new NodeParameterSampler(); } else { throw new Exception("Unsupported generic format"); } if (Generics.ContainsKey(keyName)) { var gen = Generics[keyName]; if (gen == null || gen.GetType() != nodeParameter.GetType()) { generics[keyName] = nodeParameter; } else { generics[keyName] = gen; } } else { generics.Add(keyName, nodeParameter); } }
public void GenericDictionaryTest1() { GenericDictionary <string, Book> dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1234", new Book(isbn: "1111", title: "C# Advanced")); Assert.Equal(expected: "C# Advanced", actual: dictionary["1234"].Title); }
public static void Add_TriesToAddNullValueToEmptyDictionary_ReturnedFalseAndKeysAndValuesAreEmpty() { var dictionary = new GenericDictionary <TKey, TValue>(); Assert.IsFalse(dictionary.Add(null)); CollectionAssert.IsEmpty(dictionary.Keys); CollectionAssert.IsEmpty(dictionary.Values); }
public void TestGenericDictionary() { var orderedNames = new List <string>(); orderedNames.Add("firstValue"); orderedNames.Add("secondValue"); orderedNames.Add("thirdValue"); orderedNames.Add("fourthValue"); var orderedGen = new List <INodeParameter>(); orderedGen.Add(new NodeParameter()); orderedGen.Add(new NodeParameterFloat()); orderedGen.Add(new NodeParameterSampler()); orderedGen.Add(new NodeParameterFloat4()); var testDict = new GenericDictionary(); testDict.Add(orderedNames[0], orderedGen[0]); testDict.Add(orderedNames[1], orderedGen[1]); testDict.Add(orderedNames[2], orderedGen[2]); testDict.Add(orderedNames[3], orderedGen[3]); //test enumeration order var counter = 0; foreach (var dictElem in testDict) { Assert.AreEqual(dictElem.Key, orderedNames[counter]); Assert.AreEqual(dictElem.Value, orderedGen[counter]); counter++; } //test serialization var clonedObject = AssetCloner.Clone(testDict); Assert.IsTrue(clonedObject is GenericDictionary); counter = 0; foreach (var dictElem in (GenericDictionary)clonedObject) { Assert.AreEqual(dictElem.Key, orderedNames[counter]); counter++; } }
void Update() { // Runtime test showing that the inspector reflects runtime additions. if (Input.GetKeyDown(KeyCode.Space)) { string newKey = "runtime example"; myGenericDict.Add(newKey, this.gameObject); Debug.LogFormat("Added '{0}' to myGenericDict.", newKey); } }
public static void Add_TriesToAddNullValueToNotEmptyDictionary_ReturnedFalseAndKeysAndValuesAreProper() { var dictionary = new GenericDictionary <TKey, TValue>(); var key = CreateSampleKey(); var value = CreateValue(key); _ = dictionary.Add(value); Assert.IsFalse(dictionary.Add(null)); CollectionAssert.AreEqual(new TKeyList { key }, dictionary.Keys); CollectionAssert.AreEqual(new TValueList { value }, dictionary.Values); Assert.AreEqual(value, dictionary[key]); }
public void AddComponent(Enums.ComponentType componentType, Components.MovementInput component, int entityId) { if (componentType == Enums.ComponentType.InputToMovement) { inputToMovement.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void AddComponent(Enums.ComponentType componentType, float component, int entityId) { if (componentType == Enums.ComponentType.MaxSpeed) { maxSpeeds.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void AddComponent(Enums.ComponentType componentType, bool component, int entityId) { if (componentType == Enums.ComponentType.IsVisible) { isVisibles.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void AddComponent(Enums.ComponentType componentType, Quaternion component, int entityId) { if (componentType == Enums.ComponentType.Rotation) { rotations.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public static void UseGenericList() { var numbers = new GenericList <int>(); numbers.Add(10); var books = new GenericList <Generics.Book>(); books.Add(new Generics.Book("Mary Poppins")); var dictionary = new GenericDictionary <string, Generics.Book>(); dictionary.Add("4ED21", new Generics.Book("Stocks")); }
private static void Main(string[] args) { var numbers = new GenericList <int>(); numbers.Add(1); var books = new GenericList <Book>(); books.Add(new Book()); var dictionary = new GenericDictionary <int, Book>(); dictionary.Add(1, new Book()); }
private void DoValueTest <K, V>(K key, V value) { GenericDictionary <K> dict = new GenericDictionary <K>(); dict.Add(key, value); dict.Get <V>(key) .Should() .BeOfType(typeof(V)); dict.Get <V>(key) .Should() .Be(value); }
public void AddTileType(string tileName, GameObject prototype, Material material) { var newTileType = Instantiate(prototype, transform); newTileType.GetComponent <Renderer>().material = material; newTileType.name = tileName; if (tilePrefabs.ContainsKey(tileName)) { DestroyImmediate(tilePrefabs[tileName]); tilePrefabs.Remove(tileName); } tilePrefabs.Add(tileName, newTileType); newTileType.SetActive(false); }
static void Main(string[] args) { Book csBook = new Book { Isbn = "1212", Title = "C#_Advanced" }; var numbers = new GenericList <int>(); numbers.Add(10); var books = new GenericList <Book>(); books.Add(new Book()); var dict = new GenericDictionary <string, Book>(); dict.Add("1234", new Book()); var NewNumber = new GenericClasses.Nullable <int>(); Console.WriteLine("Has Value? " + NewNumber.HasValue); Console.WriteLine("The value is: " + NewNumber.GetValueOrDefaultValue()); string ppath = string.Format("C:\\Users\\Mia\\Desktop\\AspNet_Practice\\Pjs\\C#NextLevel\\c#Generics_Delegate\\Generic-Delegate_solu\\Generic-Delegate\\imgs\\sun.png"); // Normal way apply filter /* PhotoProcessor pp = new PhotoProcessor(); * pp.ProcessPhoto(ppath); */ // Delegate Way to do Filter PhotoFilters pf = new PhotoFilters(); PhotoProcessor pp = new PhotoProcessor(); // Apply build-in Delegate System.Action<T> Action <Photo> FilterHandler = pf.ApplyBrightness; FilterHandler += pf.Resize; FilterHandler += ApplyNewFilter; pp.PhotoProcess(ppath, FilterHandler); Console.WriteLine("Press Enter to Quite..."); while (Console.ReadKey().Key != ConsoleKey.Enter) { } }
void IDictionary.Add(object key, object value) { if (_dictionary != null) { _dictionary.Add(key, value); } #if HAVE_READ_ONLY_COLLECTIONS else if (_readOnlyDictionary != null) { throw new NotSupportedException(); } #endif else { GenericDictionary.Add((TKey)key, (TValue)value); } }
public void Execute() { var book = new Book { ISBN = "123", Title = "C#", Price = 50.29f }; var books = new GenericList <Book>(); books.Add(book); books.Add(new Book()); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1234", new Book()); var number = new Generics.Nullable <int>(); Console.WriteLine($"Has value ? {number.HasValue}"); Console.WriteLine($"Value: {number.GetValueOrDefault()}"); }
public void AddComponent(Enums.ComponentType componentType, Vector3 component, int entityId) { if (componentType == Enums.ComponentType.Position) { positions.Add(entityId, component); } else if (componentType == Enums.ComponentType.Direction) { directions.Add(entityId, component); } else if (componentType == Enums.ComponentType.Scale) { scales.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
private static void Main(string[] args) { var numbers = new GenericList <int>(); numbers.Add(123); var test = new GenericList <object>(); test.Add(new { Name = "asd" }); var test2 = new GenericDictionary <string, object>(); test2.Add("asd", new { Name = "asd" }); var test3 = new Nullable <int>(); System.Console.WriteLine("Has value: {0}, Value: {1}", test3.HasValue, test3.GetValueOrDefault()); //var test3 = new Nullable<int>(5); //System.Console.WriteLine("Has value: {0}, Value: {1}", test3.HasValue, test3.GetValueOrDefault()); }
static void Main(string[] args) { var book = new Book { Id = 1, Name = "FixItNooo" }; var books = new GenericList <Book>(); books.Add(book); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("test", book); var number = new Generics.Nullable <int>(); Console.WriteLine("Has Value?" + number.HasValue); Console.WriteLine("Value" + number.GetValueOrDefault()); Console.WriteLine("Hello World!"); }
static void Main(string[] args) { //Exception Hnadeling StreamReader streamReader = null; try { streamReader = new StreamReader(@"c:\test.zip"); var content = streamReader.ReadToEnd(); throw new Exception("!"); } catch (Exception ex) { Console.WriteLine("Error Occurred!"); } finally { if (streamReader != null) { streamReader.Dispose(); } } ///Or /// StreamReader streamReader = null; try { //using (var StreamReader = new StreamReader(@"c:\test.zip")) //{ // var content = streamReader.ReadToEnd(); //} var youtube = new YouTubeApi(); var vids = youtube.GetVideos("user"); } catch (Exception ex) { Console.WriteLine(ex.Message); } //Dynamics dynamic dynamic = "test"; dynamic = 10; dynamic a = 10; dynamic bbb = 5; var c = a + bbb; int d = a; long e = d; //Nullables DateTime?date = null; Console.WriteLine(date.GetValueOrDefault()); Console.WriteLine(date.HasValue); //Console.WriteLine(date.Value); DateTime date2 = date.GetValueOrDefault(); DateTime?date3 = date2; ///Linq Extension Methods var books1 = new BookRepository().GetBooks(); var cheapBooks1 = books1.Where(x => x.Price < 10).OrderBy(x => x.Title); //Linq Query Operator var cheaperBooks = from b in books1 where b.Price < 10 orderby b.Title select b.Title; //Extensions string post = "this is long long long post..."; var shortenedPost = post.Shorten(3); Console.WriteLine(shortenedPost); //Events var video = new Video() { Title = "Video Title 1" }; var videoEncoder = new VideoEncoder(); /// Publisher var mailService = new MailService(); // subscriber var messageService = new MessageService(); videoEncoder.videoEncoded += mailService.OnVideoEncoded; videoEncoder.videoEncoded += messageService.OnVideoEncoded; videoEncoder.Encode(video); // => const int factor = 5; Func <int, int> multipler = n => n * factor; Console.WriteLine(multipler(5)); var books = new BookRepository().GetBooks(); //var cheapBooks = books.FindAll(IsCheaperThan10Dollars); var cheapBooks = books.FindAll(b => b.Price < 10); foreach (var book in cheapBooks) { Console.WriteLine(book.Title); } //Delegates var photo = new PhotoProcessor(); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; photo.Process("test", filterHandler); //Generics var numbers = new Generic <int>(); numbers.Add(10); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1", new Book()); var NUMBER = new AdvancedTopics.Nullable <int>(); Console.WriteLine("Has Value? " + NUMBER.HasValue); Console.WriteLine("Value: " + NUMBER.GetValueOrDefault()); //Or You can use System.Nullable for this purpose. }