skip to Main Content

I have a .Net solution. There are 2 projects inside it – Console App and Class Library.

I have followed this docs https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?pivots=dotnet-6-0.

However, this solution works only with a single input. How can I pass multiple inputs from console to my function in a library?

Console app:

using StringLibrary;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Enter your data");
            string firstline = Console.ReadLine();
            string secondline = Console.ReadLine();
            string thirdline = Console.ReadLine();

            string input = string.Concat(firstline, secondline, thirdline);
            Console.WriteLine("This triangle exists?" +
                              $"{(input.CheckTriangleExistance())}");
            Console.WriteLine();
        
    }
}

Library

namespace StringLibrary;

public static class StringLibrary

{
    public static bool CheckTriangleExistance(string f, string s, string t)
    {
        int a = int.Parse(f);
        int b = int.Parse(s);
        int c = int.Parse(t);

        return a > 0 && b > 0 && c > 0
               && a + b > c
               && a + c > b
               && b + c > a;
    }
}

2

Answers


  1. This way?

    string firstline = Console.ReadLine();
    string secondline = Console.ReadLine();
    string thirdline = Console.ReadLine();
    
    Console.WriteLine("This triangle exists?" +
        $"{(StringLibrary.CheckTriangleExistance(firstline, secondline,thirdline))}");
    
    Login or Signup to reply.
  2. I strongly suggest you keep the "computation" seperate from the display.

    static void Main(string[] args)
    {
        Console.WriteLine("Enter your data");
            string firstline = Console.ReadLine();
            string secondline = Console.ReadLine();
            string thirdline = Console.ReadLine();
    
     
            bool resultOne = StringLibrary.CheckTriangleExistance(firstline, secondline, thirdline);
    
            Console.WriteLine("This triangle exists? = '{0}'", resultOne);
            Console.WriteLine();
        
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search