Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:01:55+00:00 2026-06-09T16:01:55+00:00

In Visual C# 2010 Express, when pressing ctr+F7 with the code below, why is

  • 0

In Visual C# 2010 Express, when pressing ctr+F7 with the code below, why is the console not opening? I have several .cs documents in the same project but I only want to execute this one.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;


namespace ConsoleRead
{
    protected class consoleread
    {
        public void GetPortName ()
    {
            string[] sPorts = SerialPort.GetPortNames();
            foreach (string port in sPorts)
            {
                var serialPort = new SerialPort();
                serialPort.PortName = port;
                serialPort.Open();
                serialPort.WriteLine("ATI"); 
                var message = Console.ReadLine(); 
            }
    }
    }
}

Many thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:01:56+00:00Added an answer on June 9, 2026 at 4:01 pm

    This is because Ctlr + F7 will execute your application. You have created a Console Application and when launching it will search for a static Main method and that will be executed inside a Console window.

    You cannot execute arbitrary code when hitting Ctrl + F7.

    If you want to execute the code in this class, you need to add some code to your Main method (which will be executed) to create an instance of this class and execute the GetPortName.

    Here is some MSDN documentation that shows how a Console Application works.

    When you look at your Project properties (right click in the solution explorer on your project and click Properties) you will see an item Startup Object. This points to the class that contains the starting point for your application. Windows will look for a Main method in that class and start running your program from there.

    I would not advice moving all your code inside Main. This will create one big function that will execute all of your logic. For a reasonobly sized program, your Main method would explode and it would be a nightmare to maintain. Partitioning code in objects that fullfill specific goals can help you with building a better maintainble program. Look into the basics of object oriented development to understand how this can help. Here is a link to Wikipedia with some info on Object Oriented Programming.

    Another thing that’s wrong with your code is that an outer class cannot be protected. You need to change protected class consoleread into public class ConsoleRead (Casing is for readability).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Microsoft Visual C# 2010 Express. I did not have access to
I am using Microsoft Visual Basic 2010 Express. I have a WPF-based project. I
I have a project I'm working on in Visual Studio 2010 Express in C++/CLI
Visual Studio 2010 Express, Windows Forms. Have made myself my first little application which
I have a visual C# 2010 express install. Built a .NET 4.0 dll that
I'm using Visual C# 2010 Express (final, not beta or anything) and I'm having
I use VisualStudio 2010 and olso have Visual C# 2010 Express installed on my
I have developed the WCF web service in vb.net in visual studio 2010 express
I am using Visual C# Studio 2010 Express and I have oakward problem. I
I'm using Visual Basic 2010 Express. I have a form that can be minimized.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.