s1 = "new"; // это не изменит первоначальный массив // так можно легко изменить переменную масива ref var s2 = ref SimpleRefReturn(stringArray, pos);
ref var refOutput = ref SampleRefReturn(stringArray, pos); // Вызов метода также требует применения ключевого слова ref — для возвращаемой переменной и для самого вызова метода
ref string output = ref SimpleReturn(stringArray, pos);
static void Main(string[] args) { #region Variables // ************* Variables *************** // //Create a variable of type int called id. Initialize it to 75. int id = 75; //Create a variable of type string called name. Initialize it to your full name. string name = "Dylan Abeyta"; //Create a variable of type bool called isValid. Initialize it to true. bool isValid = true; //Create a variable of type int called userID. Don't initialize this value. (In C#, ints default to 0) int userID; //Create a variable of type string called state. Don't initialize this value. (In C#, strings default to null) string state; //Create a variable of type bool called hasRan. Don't initialize this value. (In C#, booleans default to false) bool hasRan; //Create a variable of type char called myCharacter. Initialize this value to "a". char myCharacter = 'a'; //Create a variable of type double called myDouble. Initialize this value to 3.14 double myDouble = 3.14; //Create a variable of type float called myFloat. Initialize this value to 3.14 (cannot convert double to float, check 1.0 slides) float myFloat = 3.14f; //Create a variable of type Random called rand. Initialize it to a new Random Object. Random rand = new Random(); #endregion #region Conditionals // ************ Conditionals ************* // //Create a variable of type bool called isValid. Initialize it to true. bool isValid = true; //if isValid is true, then console writeline "isValid is true" if (isValid == true) { Console.WriteLine("isValid is True"); } //else if isValid is not true, then console writeline "isValid is not true" else if (isValid != true) { Console.WriteLine("isValid is not true"); } //Create a variable of type int called x. Initialize it to 75. int x = 75; //Create a variable of type int called y. Initialize it to 100. int y = 100; //If x is greater than y, then console writeline "X is Greater than Y" if (x > y) { Console.WriteLine("x is greater than y"); } //else if x is equal to y, then console writeline "X is equal to Y" else if (x == y) { Console.WriteLine("x is equal to y"); } //else, then console writeline "X is less than Y" else { Cosnole.WriteLine("x is less than y"); } ; //Create a variable of type string called country. Initialize it to "Mexico". string country = "Mexico"; //Create a variable of type int called age. Initialize it to 18. int age = 18; //If country is "Mexico" and age is greater than or equal to 18 then console writeline "You can legally drive" if (country == "Mexico" && age >= 18) { Console.WriteLine("you can legally drive"); } //else if country is not "Mexico" and age is greater than or equal to 16 then console writeline "You can legally drive" else if (country != "Mexico" && age >= 16) { Console.WriteLine("you can legally drive"); } //else console writeline "you cannot legally drive" else { Console.WriteLine("you cannot legally drive"); } #endregion #region Loops // **************** Loops **************** // //for loop starting at i = 0 and continue while i < 10, incrementing by 1. Console writeline the value of i each time. for (int i = 0; i < 10; i++) { Console.WriteLine(i); } //for loop starting at i = 0 and continue while i < 30, incrementing by 2. Console writeline the value of i each time. for (int i = 0; i < 30; i += 2) { Console.WriteLine(i); } //for loop starting at i = 30 and continue while i >= 0, decrementing by 1. Console writeline the value of i each time. for (int i = 30; i >= 0; i--) { Console.WriteLine(i); } //for loop starting at i = 30 and continue while i > 0, decrementing by 3. Console writeline the value of i each time. for (int i = 30; i > 0; i -= 3) { Console.WriteLine(i); } //Create an int variable called index, initialize it to 0. int index = 0; //while index < 10 Console writeline index. while (index < 10) { Console.WriteLine(index); index++; } //reset index variable to 0 int index = 0; //while index < 0 console writeline index while (index < 0) { Console.WriteLine(index); index++; } //Reset index variable to 0 int index = 0; //do-while index < 10 console writeline index. do { Console.WriteLine(index); index++; } while (index < 10); //reset index variable to 0 int index = 0; //do-while index < 0 console writeline index do { Console.WriteLine(index); index++; } while (index < 0); //Create an int variable called input, initialize to 0 int input = 0; //Accept user input with Console.ReadLine and parse it into an integer with int.Parse. Store in input variable. input = int.Parse(Console.ReadLine()); //do-while input does not equal -1, console writeline "Input -1 to end program, input any other number to continue" do { Console.WriteLine("input -1 to end program, input any other nuumber to continue"); } while (input != -1); #endregion #region Arrays // *************** Arrays **************** // //Create an array of type int and of size 10 called intArray. Don't initialize any data. (Remember, ints default to 0 so you now have an array of 10 0's.) int[] intArray = new int[10]; //Create an array of type string and of size 5 called stringArray. Don't initialize any data. string[] stringArray = new string[5]; //For the following, change each index individually. Do not use a loop or assignment on declaration intArray[0] = 0; intArray[1] = 1; intArray[2] = 2; intArray[3] = 3; intArray[4] = 4; intArray[5] = 5; intArray[6] = 6; intArray[7] = 7; intArray[8] = 8; intArray[9] = 9; //Populate intArray with data following the formula: data = index * 3. IE the 3rd element of intArray will equal 9. intArray[0] *= 3; intArray[1] *= 3; intArray[2] *= 3; intArray[3] *= 3; intArray[4] *= 3; intArray[5] *= 3; intArray[6] *= 3; intArray[7] *= 3; intArray[8] *= 3; intArray[9] *= 3; //Populate stringArray with the following data: firstName, lastName, city, state, country stringArray[0] = "firstName"; stringArray[1] = "lastName"; stringArray[2] = "City"; stringArray[3] = "state"; stringArray[4] = "Country"; //for the following use a loop to assign the data into the arrays. //set each index data of intArray using the following formula: data = index * 2 + 1. IE the 3rd element will equal 7 for (int i = 0; i < 10; i++) { intArray[i] = i * 2 + 1; } //set each index data of stringArray to "The current index is i" where i is the actual value of i for (int i = 0; i < 5; i++) { stringArray[i] = ("the current is " + i); } //reset intArray to be a new int array of size 5. In the same line (hint, use { }) set the values to 0,1,2,3,4. int[] intArray = new intArray[5] { 0, 1, 2, 3, 4 }; //reset stringArray to be a new string array of size 3. In the same line (hint, use { }) set the values to "buddy", "guy", "Friend" string[] stringArray = new stringArray[3] { "buddy", "guy", "Friend" }; //for int i = 0, continue for the length of intArray, and increment i + 1, console writeline the value of intArray for (int i = 0; i < intArray.Length; i++) { Console.WriteLine(intArray[i]); } //for int i = 0, continue for the length of stringArray, and increment i + 1, console writeline the value of stringArray for (int i = 0; stringArray.Length; i++) { Console.WriteLine(stringArray[i]); } //iterate over (AKA use a for loop) intArray similarly to what you did above, but do it backwards. Print the last index first, and the 0th index last. for (int i = intArray.Length; i > 0; i--) { Console.WriteLine(intArray[i]); } //iterate over (AKA use a for loop) stringArray similarly to what you did above, but do it backwards. Print the last index first, and the 0th index last. for (int i = stringArray.Length; i > 0; i--) { Console.WriteLine(stringArray[i]); } #endregion }
ref var refOutput = ref SampleRefReturn(stringArray, pos);
static void Main(string[] args) { //character type info //heros //Warrior Heros Warrior = new Heros(); Warrior.heroType = 1; Warrior.heroName = "Warrior"; Warrior.heroHealth = 125; Warrior.heroAttack = 60; Warrior.heroSpeed = 40; Warrior.heroRange = 0; //Archer Heros Archer = new Heros(); Archer.heroType = 2; Archer.heroName = "Archer"; Archer.heroHealth = 110; Archer.heroAttack = 20; Archer.heroSpeed = 55; Archer.heroRange = 60; Archer.experience = 0; //Mage Heros Mage = new Heros(); Mage.heroType = 3; Mage.heroName = "Mage"; Mage.heroHealth = 100; Mage.heroAttack = 30; Mage.heroSpeed = 50; Mage.heroRange = 40; Mage.experience = 0; //Assassin Heros Assassin = new Heros(); Assassin.heroType = 4; Assassin.heroName = "Assassin"; Assassin.heroHealth = 95; Assassin.heroAttack = 40; Assassin.heroSpeed = 60; Assassin.heroRange = 30; Assassin.experience = 0; //monsters //AngryTree DungeonMonsters AngryTree = new DungeonMonsters(); AngryTree.monsterType = 1; AngryTree.monsterName = "Angry Tree"; AngryTree.monsterHealth = 50; AngryTree.monsterAttack = 25; AngryTree.monsterSpeed = 34; AngryTree.monsterRange = 5; AngryTree.experience = 150; //RangeRoot DungeonMonsters RageRoot = new DungeonMonsters(); RageRoot.monsterType = 2; RageRoot.monsterName = "Rage Root"; RageRoot.monsterHealth = 30; RageRoot.monsterAttack = 10; RageRoot.monsterSpeed = 30; RageRoot.monsterRange = 30; RageRoot.experience = 150; //SlingDemon DungeonMonsters SlingDemon = new DungeonMonsters(); SlingDemon.monsterType = 3; SlingDemon.monsterName = "Sling Demon"; SlingDemon.monsterHealth = 85; SlingDemon.monsterAttack = 10; SlingDemon.monsterSpeed = 35; SlingDemon.monsterRange = 15; SlingDemon.experience = 75; //Goblin DungeonMonsters Goblin = new DungeonMonsters(); Goblin.monsterType = 4; Goblin.monsterName = "Goblin"; Goblin.monsterHealth = 100; Goblin.monsterAttack = 30; Goblin.monsterSpeed = 25; Goblin.monsterRange = 0; Goblin.experience = 75; //game start screen Console.WriteLine("________ _________ .__ "); Console.WriteLine("\\______ \\ __ __ ____ ____ ____ ____ ____ \\_ ___ \\____________ __ _ _| | ___________ "); Console.WriteLine("| | \\| | \\/ \\ / ___\\_/ __ \\/ _ \\ / \\ / \\ \\/\\_ __ \\__ \\ \\/ \\/ / | _/ __ \\_ __ \\ "); Console.WriteLine("| ` \\ | / | \\/ /_/ > ___( <_> ) | \\ \\ \\____| | \\// __ \\ /| |_\\ ___/| | \\/"); Console.WriteLine("/_______ /____/|___| /\\___ / \\___ >____/|___| / \\______ /|__| (____ /\\/\\_/ |____/\\___ >__| "); Console.WriteLine(" \\/ \\//_____/ \\/ \\/ \\/ \\/ \\/ "); Console.Read(); //hero selection //monster array string[] DungeonMonsters = new stringArray[4] { AngryTree, SlingDemon, Goblin, RageRoot }; //xp }