Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, March 2, 2019 8:03 PM
Using Visual Studio 2017 I created a new empty solution. I added a Console App project to the solution which created a class named Program with a static void Main(string[] args) function. I added an additional class named "CData" with only one constructor which takes an integer and calculates a time to process based on the integer.
I added code to the Main function to use the command line argument(s) and display the processing time. Here is the Program class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataSource
{
class Program
{
static int Main(string[] args)
{
int retVal = 0;
if (args.Count<string>().Equals(0))
{
Console.WriteLine("usage: DataSource <Any Integer>");
}
else
{
try
{
int val = 0;
val = Convert.ToInt32(args[0]);
CData dat = new CData(val);
double res = dat.RequestTime.TotalSeconds;
Console.WriteLine($"Processing time: {res} seconds.");
}
catch (Exception ex)
{
retVal = ex.GetHashCode();
Console.WriteLine(ex.Message);
}
}
Console.ReadLine();
return (retVal);
}
}
}
How does this not work?
Scaling the Cliffs of Insanity
All replies (4)
Sunday, March 3, 2019 12:58 AM | 1 vote
Hello,
Why would you create a class Program when the default class is Program when creating a Console project?
No matter if I take your code (and the missing code) it compiles just fine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataSource
{
class Program
{
static int Main(string[] args)
{
int retVal = 0;
if (args.Count<string>().Equals(0))
{
Console.WriteLine("usage: DataSource <Any Integer>");
}
else
{
try
{
int val = 0;
val = Convert.ToInt32(args[0]);
CData dat = new CData(val);
double res = dat.RequestTime.TotalSeconds;
Console.WriteLine($"Processing time: {res} seconds.");
}
catch (Exception ex)
{
retVal = ex.GetHashCode();
Console.WriteLine(ex.Message);
}
}
Console.ReadLine();
return (retVal);
}
}
internal class CData
{
public CData(int val)
{
throw new NotImplementedException();
}
public TimeSpan RequestTime { get; set; }
}
}
Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
NuGet BaseConnectionLibrary for database connections.
Sunday, March 3, 2019 1:28 AM | 2 votes
Using Visual Studio 2017 I created a new empty solution. I added a Console App project to the solution which created a class named Program with a static void Main(string[] args) function. I added an additional class named "CData" with only one constructor which takes an integer and calculates a time to process based on the integer.
How does this not work?
My guess is that your steps:
(1) Created an empty project.
(2) Added a Console *project* to the Solution
resulted in the Solution having *two* projects in it.
The first project created - the Empty project - is probably flagged as the
Startup project.
If you look at the Solution Explorer window it will likely show that Empty
Project in Bold type and the Console Project you added to the Solution in
Normal font. Try this:
In the Solution Explorer window, right-click on the Console App project and
from the menu click on "Set as Startup Project". Save, rebuild and run.
- Wayne
Sunday, March 3, 2019 1:40 AM
To add to my prior comments, if you have two Projects in the Solution - one
an Empty Project and the other a Console Project - only the Console Project
can be compiled and linked. The Empty project cannot be built without errors
as you have seen. You probably should remove the Empty project from the
Solution.
- Wayne
Monday, March 4, 2019 7:45 AM | 1 vote
Hi Maineac,
>>How does this not work?
How does it not work, there are no specific steps to restore, and related error messages
From your code, I add some command line arguments and can debug it.
Best Regards
Yong Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].