How do I do this? Can this be done through code in C# ? I use this code to do this but it doesn't work .
using System;
using System.Diagnostics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Process.Start(#"C:\wamp64\wampmanager.exe");
}
}
}
I need to compile via csc.exe this code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Scripting;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Scripting.FileSystemObject fso = new Scripting.FileSystemObject();
Scripting.Folder folder = fso.GetFolder(#"E:\backup_SQL_Planet\");
Int64 dirSize = (Int64)folder.Size;
string abc = Convert.ToString(dirSize);
Console.WriteLine(abc);
}
}
}
when i execute csc.exe there was a problem with reference of (using Scripting;)
How do I reference using Scripting?
I am writing the code right, but getting error - missing namespace or assembly reference.Is there something wrong with the code or I am missing something?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int sum = 0;
int[] arr = new int[] { 1, 2 };
do
{
{
sum += arr[1];
Console.WriteLine("Wow");
i++;
}
}
while (i < 3);
}
}
}
Error is : Error Cannot initialize type 'int' with a collection initializer because it does not implement 'System.Collections.IEnumerable
My namespace ended in Console (i.e. MyProject.Console) which messed up the calls to Console.Write. In this case, either write the fully qualified name System.Console.Write or change the namespace.
i am writing the code right
Don't start with this assumption. Always start with the assumption that the compiler is correct, and your code is wrong.
You haven't shown any using directives. In this case all you need is
using System;
(Either at the very top of your code or within the namespace declaration.)
or change your WriteLine call to:
System.Console.WriteLine("Wow");
If that doesn't fix it (or if you've already got such a using directive but forgot to include it), then your project is probably somewhat broken - it's not like you're using any exotic types.
Import the System namespace or just use System.Console.WriteLine("...");
using System;
namespace TestNs
{
public class Test
{
static void Main()
{
Console.WriteLine("Hello World");
}
}
}
I faced a similar problem. The namespace name I used ended with .Console, so there was a conflict with System.Console
using System;
namespace Test.Console
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
I changed Test.Console to Test.ConsoleApp, and problem fixed for me
using System;
namespace Test.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
The minimum for your console app should have this
using System;
using System.Collections.Generic;
using System.Text;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
}
}
}
thanks to all for help i managed to solve the problem with the help of you guys :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int i = 0; //initialize integer i=0
int sum = 0; // initialize integer sum = 0;
int[] arr = new int[]{1, 2, 3, 4}; // array containing 4 integers elements
do
{
{
sum+=arr[i]; //sum each integer in array and store it in var sum
i++; //increment i for each element of array
Console.WriteLine(sum); //output the var sum conatining values after each increment
}
}
while(i<=3); //check condition for number of elements in array
}
}
}
Using a namespace of Myproject.App also causes problems, in the same way as MyProject.Console (as per contactmatt's answer, above).
Why this work:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronRuby;
class Tutorial
{
static void Main(string[] args)
{
var engine = Ruby.CreateEngine();
engine.Runtime.Globals.SetVariable("Holly",new Holly("Test"));
engine.Execute("Holly.Say");
Console.ReadLine();
}
}
class Holly
{
string speech;
public Holly(string speech)
{
this.speech = speech;
}
public void Say()
{
Console.WriteLine("Hollu said " + this.speech);
}
}
and this is not work
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronRuby;
class Tutorial
{
static void Main(string[] args)
{
var engine = Ruby.CreateEngine();
engine.Runtime.Globals.SetVariable("Mouse",new Holly("Test"));
engine.ExecuteFile("./test.rb");
Console.ReadLine();
}
}
class Holly
{
string speech;
public Holly(string speech)
{
this.speech = speech;
}
public void Say()
{
Console.WriteLine("Hollu said " + this.speech);
}
}
Try this
engine.ExecuteFile(#"..\test.rb");
Also wrap your code in try/catch statement and check for exception
try
{
var engine = Ruby.CreateEngine();
engine.Runtime.Globals.SetVariable("Holly",new Holly("Test"));
engine.ExecuteFile(#"..\test.rb");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
How to if I want to write an application that launches Firefox with arguments ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Launcher
{
public static class Program
{
public static void Main(string[] args)
{
Process.Start("C:/Program Files/Mozilla Firefox/firefox.exe");//this is ok
Process.Start("C:/Program Files/Mozilla Firefox/firefox.exe -P MyProfile -no-remote");// this doesn't work
}
}
}
You will need to specify the process.StartInfo.Arguments
See this question: Calling an application from ASP.NET MVC
You will need to use the process.StartInfo.Arguments, as shown here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Launcher
{
public static class Program
{
public static void Main(string[] args)
{
Process firefox = new Process();
firefox.StartInfo.FileName = #"C:\Program Files\Mozilla Firefox\firefox.exe";
firefox.StartInfo.Arguments = "-P MyProfile -no-remote";
firefox.Start();
}
}
}