I am trying to make a C# Stress script but it keeps giving me the error: Error Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Skyper;
using SKYPE4COMLib;
using System.Net;
namespace Skyper.plugins
{
public static class Help
{
public static string Description
{
get
{
return "Stresser";
}
}
public static void Execute(string[] Params, int chat, string username)
{
Skyper.SendMessage(chat, Params[1] + "" + new WebClient().DownloadString("http://example.com/stresser/api.php?key=examplekey&host=" + Params[1]));"&port=&time=&method=";
}
}
}
How this script will work is users in Skype will type in !stress ip, port, time, method and then it will submit it to the API.
Following is a simple string, which is not assigned to any thing,
"&port=&time=&method=";
So may be you can use something like:
Skyper.SendMessage(chat, Params[1] + "" + new WebClient().DownloadString("http://example.com/stresser/api.php?key=examplekey&host=&port=&time=&method=" + Params[1])");
or change that string properly with double quotes and brackets end symbols
Related
Where exactly is the problem? "System.ArgumentNullException: 'Value cannot be null.
Parameter name: path'" why could this be? Is there anyone who can help? Could the question have something to do with "Textwriter"?
here is my code
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Result
{
/*
* Complete the 'aVeryBigSum' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER_ARRAY ar as parameter.
*/
public static long aVeryBigSum(List<long> ar)
{
long sum=0;
for(int i=0; i<= ar.Count;i++) {
sum += ar[i];
}
return sum;
}
}
class Solution
{
public static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter(#System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int arCount = Convert.ToInt32(Console.ReadLine().Trim());
List<long> ar = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(arTemp => Convert.ToInt64(arTemp)).ToList();
long result = Result.aVeryBigSum(ar);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
I just ran your solution directly on Hackerrank and it does not throw that exception, so I would assume that you are running it locally.
When you run those solutions locally you need to be careful with the Environment Variables.
In this case the program expects an Environment Variable called OUTPUT_PATH which you probably did not set on your machine, but it is set on Hackerrank.
According to Microsoft, Environment.GetEnvironmentVariable returns:
The value of the environment variable specified by variable, or null if the environment variable is not found.
ı solved the problem. change the function like this:
public static long aVeryBigSum(List<long> ar)
{
long sum=0;
foreach(long item in ar) {
sum = sum +item;
}
return sum;
}
I'm using String interpolation in the code behind, and now I need to take part of it to a class.
when I do it, I get error "CS1056: Unexpected character '$'"
even a very simple code gives the error right on running (not on build):
string MailSubject = $"this is your score: {userScore}";
this part of code is part of the FaceClass.CS file
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
namespace ns.App_Code
{
public class FakeClass
{
public static void Check_Next_In_Line(int score)
{
int temp = Fake2Class.GetData();
if (temp == 0)
{
string MailSubject = "";
string MailBody = "";
MailBody = $"Your score: {score}";
/*
mail send function
*/
}
}
}
}
I'm using .NET Framework 4.8
String Interpolation works for me in a aspx code behind but not in a method within a class. If I want to refactor a part of code becuase it is needed more than once - it won't work
Hi an alternative solution to what you are looking for may be would be to use string format. Something like below
int userscore;
string MailSubject = string.Format("this is your score: {0}", userscore);
i am starting to learn C#, my first language i learned is Python and i switched to Visual Studio Code for it from Pycharm.
I am trying to code a simple TicTacToe as exercise, when i loop trough my TicTacToe grid to see if one of the empty fields marked with numbers is still avaliable, i get an unexpected output.
The expected output would be 1-9, but its not, i am not allowed to post images so not sure how to say/show it.
When i use char as data type the correct value seems to be there in '' as second value, but how do access it?
in both cases comparision operator do not yield the expected results!
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public static class Programm
{
static int meow = 1;
static string board_roof = "-------";
static string board_mid1 = "|1|2|3|";
static string board_mid2 = "|4|5|6|";
static string board_mid3 = "|7|8|9|";
static string board_all_default = board_roof + Environment.NewLine + board_mid1 + Environment.NewLine +board_mid2 + Environment.NewLine +board_mid3 + Environment.NewLine + board_roof;
public static void Main(string[] args) {
Acces_board2(meow);
}
public static void Acces_board2(int lfm) {
for(int gas=0; gas<board_all_default.Length; gas++) {
bool result = char.IsNumber(board_all_default[gas]);
if (result) {
Console.WriteLine($"{board_all_default[gas]} , {lfm}");
if(lfm < board_all_default[gas]) {
Console.WriteLine($"True");
}
}
}
}
}
}
doesnt matter if i use
if (lfm < board_all_default[gas])
or
int checkme = board_all_default[gas];
if (lfm < checkme)
it never works, that would be no issue in python, i have no clue whats happening
i have method where i create random number once called from other class. Making delegate and pointing it to that method invokes that method itself and random number is generated. I can't access that method without creating new random number. I want to get that method returned value with delegate. By writing it "Console.WriteLine(some_kind_delegate);" gives me path "Consoleapp8.class+method".
P.S although when i use delegate when comparing his pointed value with other variable answer is correct.
Screenshot in visual studio environment with my comments: https://www.dropbox.com/s/cx6858x5qen7k1p/dayum.PNG?dl=0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
abstract class variklis
{
delegate int delegatas();
static int litrazas;
static void Main()
{
Console.WriteLine("serijinis bloko numeris: " + blokas.serijinis_bloko_numeris());
Console.WriteLine("variklio tipas: In-line " + blokas.vidus() + " cilindrai");
Console.WriteLine("stumokliu skaicius: " + stumokliai.stumokliuskaicius);
Console.WriteLine("stumokliu kodas: " + stumokliai.stumokliu_kodas());
Console.Write("galimas variklio litrazas siam automobiliui: ");
int.TryParse(Console.ReadLine(), out litrazas);
litrazui();
}
public static void litrazui()
{
string damm;
delegatas zeta;
zeta = blokas.litrazas;
Console.WriteLine(zeta);
if (zeta() <= litrazas)
{
damm = "variklis tinkamas siam automobiliui";
}
else
{
damm = "variklis netinkamas siam automobiliui";
}
Console.WriteLine(damm);
}
}
}
The problem is due to the Console.WriteLine implicitely converting the delegate to a string, which is Consoleapp8.class+method, instead you need to invoke the function be appending parenthesis to the end of it.
Console.WriteLine(zeta());
And to answer the question in your comment. If you need to store the int that is the return from the delegate you can do apply the same principle from above, by appending parenthesis to invoke the function.
int number = zeta();
I'm trying to implement MS LogParser in a C# application. This compiles fine but inexplicably crashes on the logQuery.ExecuteBatch() method. The try/catch block doesn't catch it unless I specifically malform the szQuery, which suggests that everything is working as it should, I'm just not getting any output.
Any thoughts on why it might be crashing or where I might find some logging?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FolderLoggingLib;
using MSUtil;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
//refLog = new BinaryInputFormat();
LogQueryClass logQuery = new LogQueryClass();
ICOMCSVOutputContext output = new COMCSVOutputContextClass();
ILogParserInputContext parse = new BinaryInputFormat();
string szFileName = #"E:\Programming\FolderLogging\2012-05-13.fbl";
string szQuery = "SELECT Folder, User, Record, DB, TO_LOCALTIME(Timestamp) AS DateTime, Operation, Checked FROM " + szFileName + " ORDER BY DateTime DESC";
try
{
logQuery.ExecuteBatch(szQuery, parse, output);
}
catch
{
};
}
}
}
Use Execute instead of ExecuteBatch:
MSUtil.ILogRecordset RecordSet = logQuery.Execute(query, oInputFormat)
If you want to export to CSV in your sample code you need to change the query by adding INTO output_file_name and run ExecuteBatch:
string szQuery = "SELECT Folder, User, Record, DB, TO_LOCALTIME(Timestamp) AS DateTime, Operation, Checked **INTO c:\out\out.csv** FROM " + szFileName + " ORDER BY DateTime DESC";