I need to create a struct storing four points. I wanted to create a Point variable, but it looks I can't use System.Drawing in console application. What should I use?
you should add a reference to System.Drawing.dll and then add using System.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
}
}
}
Related
This question already has an answer here:
'Class.function' doesn't exist in current context while using a self made NuGet Package
(1 answer)
Closed 5 months ago.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
}
}
}
And another class in another file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rock_Paper_Scissors
{
internal class ComputerGenerateSign
{
public string computer;
Console.ReadKey()
}
}
Why Visual Studio code have a problem ?>"Error IDE1007 The name 'Console.ReadKey' does not exist in the current context"
Use 'Console.ReadKey();' in the body of a method, That way it will recognize. You didn't write a method inside the 'ComputerGenerateSign' class like the class 'program' has the main method. hope this helps.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rock_Paper_Scissors
{
public class ComputerGenerateSign
{
public void method1()
{
public string computer;
Console.ReadKey();
}
}
}
You have made function call in class which was not allowed. In class you can define properties, fields and functions.
You need to call that function inside a function body.
Main.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rock_Paper_Scissors;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
ComputerGenerateSign obj=new ComputerGenerateSign();
obj.WaitForUserInput();
}
}
}
And another class in another file
using System;
using System.Text;
namespace Rock_Paper_Scissors
{
public class ComputerGenerateSign
{
public string computer;
public void WaitForUserInput()
{
Console.ReadKey();
}
}
}
I opened a new project right now, and I opened a new class there with a "Main" inside it.
I already read whole over the internet about it and I already got that it happens because I have more than one "Main" method, but I read that when you choose inside the - Properties --> Startup object - your "Main" that you want to open it should be fixed.
The problem is that it doesn't show them at all.
What am I suppose to do?
That's the Error:
CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
My classes:
First -
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerProject
{
internal class Program
{
static void Main(string[] args)
{
}
}
}
Second -
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerProject
{
internal class FakeCoin
{
static void Main(string[] args)
{
Console.WriteLine("Hi");
}
}
}
Third -
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerProject
{
internal class WhyLikeThat
{
static void Main(string[] args)
{
}
}
}
Properties:
https://i.stack.imgur.com/5wkYV.png
As described in the official documention, you just need to specify your entry point in your .csproj by using the <StartupObject> or the <MainEntryPoint> tag.
In your case you should be writting something like <StartupObject>BeginnerProject.FakeCoin</StartupObject> if you want the second class to be your entry point.
When I try to compile a simple application I made in VSCode with 2 .cs files one with a class, and the other with the main method, I get an error: cannot find type or namespace "MyClass". I do not understand why this happens, as I have put both the main method and class declaration in the same namespace.
MyClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace classes_test.src
{
public class MyClass
{
public void testFunc() { Console.WriteLine("Hello World!"); }
}
}```
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace classes_test
{
class Program
{
static void Main(string[] args)
{
MyClass myClass = new MyClass();
myClass.testFunc();
Console.WriteLine("Hello World!");
}
}
}
I want the console to print Hello World!, but instead I get this error.
classes_test.src
and
classes_test
are not the same Namespace.
In order to set your class visible to the main method, you have to use the following using statement.
using classes_test.src;
This is a quite common mistake, especially for those who are c#-newbie.
Including a namespace, DOES NOT include the subnamespaces
Error 1 Inconsistent accessibility: field type 'Youtube_Manager.Ffmpeg' is less accessible than field 'Youtube_Manager.ScreenShot.fmpeg'
In a class top i added:
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
namespace Youtube_Manager
{
public class ScreenShot
{
#region Global Variables
public static Ffmpeg fmpeg;
Then i'm calling to use fmpeg in another class in a timer click event:
ScreenShot.fmpeg.Close();
And i'm getting in the class ScreenShot on the fmpeg the error:
Error 1 Inconsistent accessibility: field type 'Youtube_Manager.Ffmpeg' is less accessible than field 'Youtube_Manager.ScreenShot.fmpeg'
And this is the top of the class Ffmpeg:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using DannyGeneral;
namespace Youtube_Manager
{
class Ffmpeg
{
NamedPipeServerStream p;
String pipename = "mytestpipe";
System.Diagnostics.Process process;
string ffmpegFileName = "ffmpeg.exe";
string workingDirectory;
public Ffmpeg()
{
Even if i change the variable fmpeg from static to public i'm getting on it the same error.
Top-level C# classes are internal by default. Internal has a lower visibility than public. Use public class Ffmpeg to make the class public.
I have two class that are almost completely identical. They both produce visual charts, the same visual chart in fact. One produces the chart for window, one produces the chart for the web. There is really only one difference in the classes ChartFactoryA uses
using System.Windows.Forms.DataVisualization.Charting;
While ChartFactoryB uses
using System.Web.UI.DataVisualization.Charting;
Basically the two charts take the same data and construct, then return the final chart. I would like some direction on creating one class out of the two so I can move it to my shared library.
This is the public and private interface of the class
public class ChartFactory
{
private const int MAX_POINTS_DISPLAYED = 5;
private const int MAX_POINTS_TRACKED = 6;
public static Chart CreateChart(UserCourse userCourse)
private static Chart InitilizeChart()
private static Chart CreateEmptyChart()
private static ChartArea CreateEmptyChartArea()
private static void SetUpAxisY(ChartArea chartArea)
private static void SetUpAxisX(ChartArea chartArea)
private static Series CreateEmptyDataSeries()
private static void AttachStripLineToChart(ChartArea chartArea)
private static void PopulateChartWithData(Chart chart, UserCourse userCourse)
private static ChartPoint[] InitilizeChartPoints(SessionsReadOnly sessions, int pointCount)
private static void PopulateChartPointsWithSessions(SessionsReadOnly sessions, int pointCount, ChartPoint[] chartPoints)
private static void DisplayChartPointsInReverse(Chart chart, ChartPoint[] chartPoints)
}
Use #define
Sample (Copied from Json.Net project)
using System;
using System.Collections.Generic;
#if !SILVERLIGHT && !PocketPC && !NET20
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Web.Script.Serialization;
#endif
using System.Text;
using NUnit.Framework;
using Newtonsoft.Json;
using System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using System.Linq;
using Newtonsoft.Json.Converters;
#if !PocketPC && !NET20 && !WINDOWS_PHONE
using System.Runtime.Serialization.Json;
#endif
using Newtonsoft.Json.Tests.TestObjects;
using System.Runtime.Serialization;
using System.Globalization;
using Newtonsoft.Json.Utilities;
using System.Reflection;
#if !NET20 && !SILVERLIGHT
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using System.Linq.Expressions;
#endif
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
using System.ComponentModel;
#endif