Использование локальной переменной, которой не присвоено значение - C# (177689)
Формулировка задачи:
Использование локальной переменной "b", которой не присвоено значение.
Не понимаю как сделать её глобальной
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string n, max, min, x, c,m ;
- int n1, max1, min1, x1, c1,m1,b;
- Console.WriteLine("Vvedite dlinnu masiva");
- n = Console.ReadLine();
- Console.WriteLine("Vvedite ogranichenie sverhu");
- max = Console.ReadLine();
- Console.WriteLine("Vvedite ogranichenie snizu");
- min = Console.ReadLine();
- n1 = Convert.ToInt32(n);
- max1 = Convert.ToInt32(max);
- min1 = Convert.ToInt32(min);
- int[] arr = new int[n1];
- Random rand = new Random();
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = rand.Next(min1, max1);
- }
- for (int g = 0; g < arr.Length; g++)
- {
- if (arr[g] == 0)
- {
- x = Console.ReadLine();
- x1 = Convert.ToInt32(x);
- arr[g] = x1;
- }
- }
- Console.WriteLine("Vvedite nachalniy element podmasiva");
- c = Console.ReadLine();
- c1 = Convert.ToInt32(c);
- Console.WriteLine("Vvedite konechniy element podmasiva");
- m = Console.ReadLine();
- m1 = Convert.ToInt32(m);
- int[] arr1 = new int[m1-c1+1];
- Array.ConstrainedCopy(arr, c1, arr1, 0, m1);
- Console.WriteLine(arr1.Length);
- int max2;
- for (int i = 0; i < arr1.Length; ++i)
- {
- if (arr1[i] > arr1[i++])
- {
- max2 = arr1[i];
- }
- else
- {
- max2 = arr1[i++];
- }
- b = max2;
- }
- Console.WriteLine(b);
- Console.Read();
- }
- }
- }
Решение задачи: «Использование локальной переменной, которой не присвоено значение»
textual
Листинг программы
- for (int i = 0; i < arr1.Length; ++i)
- {
- if(i+1<arr1.Length&&i<arr1.Length-1){
- if (i+1<arr1.Length&&arr1[i] > arr1[i++])
- {
- if (i<arr1.Length)
- max2 = arr1[i];
- if(i==arr1Length-1)
- Console.WriteLine(b);
- if (arr1[i] == arr1[i++])
- b = max2;
- }
- else
- {
- if (i+1<arr1.Length)
- max2 = arr1[i++];
- if(i==arr1Length-1)
- Console.WriteLine(b);
- if (arr1[i] == arr1[i++])
- b = max2;
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д