X
X
Xandiem2021-11-22 14:57:06
C++ / C#
Xandiem, 2021-11-22 14:57:06

Separate data types or one var?

It turned out that on real numbers in Russian wasps, you need to use not a dot, but commas.

My IDE (I use Rider because there are no ide norms for Linux) prompted me to replace double with var ... And now my question is: what is var, is it a universal variable or what is the essence of var (a) in general?
PS: Perhaps I will attach 2 small codes with and without var, so that it would be clear what I mean:

Code with var

using System;

public class MainClass
{
    public static void Main()
    {
        var a = Convert.ToDouble(Console.ReadLine()); // Получаем ввод с клавиатуры но не используя тип переменной double а используя var как универсальное
        var b = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine((a + b) / 2); //делаем все решение и выводим
    }
}


Code without var:

using System;

public class MainClass
{
    public static void Main()
    {
        double a = Convert.ToDouble(Console.ReadLine()); // Получаем ввод с клавиатуры но уже НЕ используя var
        double b = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine((a + b) / 2); //делаем все решение и выводим
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2021-11-22
@Xandiem

https://docs.microsoft.com/ru-ru/dotnet/csharp/lan...
var - says "there will be a variable next", and the compiler already determines the type of the variable.
In your specific example, it is clear that both variables are double from the right side of the assignment.

D
Davilkus Games, 2021-11-22
@Davilkus

You can use var, but in order to better delve into the topic, it’s better to know what type of data you need to put in this or that situation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question