|
You've got a bigger problem with UDP. Your client must be tolerant of lost or corrupted data. UDP does not guarantee delivery of any packet nor does it even guarantee the order in which they arrive!
|
|
|
|
|
Yes yes i know, udp maybe in the future. Now let's work on tcp
|
|
|
|
|
I have a submenu on master page which has two webforms(candidate and add new) in it.when I click on candidate page and do my work. then if I have to go to add new page then I have to click on menu and click on add new page. Is there any way if i click on add new page there should be link label on top of page that shows candidate page. So that if I click that It should take me to a candidate page.
It is an emergency any help would be appreciated
|
|
|
|
|
Member 13189268 wrote: It is an emergency In what way? But as to your main question, you can put links in any page you wish in order to switch from one to another.
|
|
|
|
|
Member 13189268 wrote: It is an emergency
Have you checked the airways? Pulse? Bleeding?
Do you require the Police, Ambulance, or Fire services?
Because I've checked here, and nobody can see an emergency anywhere...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i have a small confusion that when we compare like == or equal function then both does the same job. u have a very basic question here.
see my program full code
int x = 1000;
int y = 1000;
if (x == y)
Console.WriteLine("Value is same");
else
Console.WriteLine("Value is not same");
if (x.Equals(y))
Console.WriteLine("Value is same");
else
Console.WriteLine("Value is not same");
if (object.ReferenceEquals(x,y))
Console.WriteLine("ref is same");
else
Console.WriteLine("ref is not same");
string s1 = "Hello";
string s2 = "Hello";
if (s1 == s2)
Console.WriteLine("Value is same");
else
Console.WriteLine("Value is not same");
if (s1.Equals(s2))
Console.WriteLine("Value is same");
else
Console.WriteLine("Value is not same");
if (object.ReferenceEquals(s1, s2))
Console.WriteLine("ref is same");
else
Console.WriteLine("ref is not same");
i know that this kind of checking if (x == y) is based on value but when i use Equals function then i saw Equals is also work like == operator....am i right ?
how to check the reference ?
if (object.ReferenceEquals(x,y))
Console.WriteLine("ref is same");
else
Console.WriteLine("ref is not same");
i saw in this case else portion execute........why because different memory is allocated for x and y ?
see more for string reference check
if (object.ReferenceEquals(s1, s2))
Console.WriteLine("ref is same");
else
Console.WriteLine("ref is not same");
in this scenario s1 and s2 ref found same which is not clear to me because s1 and s2 ref should be different because two are different variable so how s1 and s2 reference check become same?
i like to know what are the best process to know value and reference is same or not whatever data type we use may be string or integer or float etc. please some one help me to understand this.
one guy said string in dotnet is interned. what is the meaning of In .NET strings are interned ? interned or internal is same ?
please discuss with a example just to clarify the meaning of string is interned in dotnet.
thanks
tbhattacharjee
|
|
|
|
|
|
What gets me is that he's been here for 13 years, and he still knows nothing about development, and can't use Google ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
"Artificial" intelligence.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
Message Closed
modified 9-May-17 6:10am.
|
|
|
|
|
Can any one suggest a better way to identify the redundant code in a class using c# code.
For Example:
Method1() body had some other method calls
Method2() body had few more other method calls including the methods in Method1().
In this case i have to identify that the method1() had the redundant code. I need to comment that.
Suggest me the best answer.
|
|
|
|
|
The only way to be sure is to understand exactly what the code is doing. There may be good logical reasons why some code is duplicated in a program.
|
|
|
|
|
Application has the legacy code.I want to remove that code.Can you suggest the better approach
|
|
|
|
|
How better? There is no automatic method of deciding what code to remove.
|
|
|
|
|
WinDiff - Wikipedia
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Below is a program that selects the coefficients and corresponds to the result. After that sorting is performed for the statement.
Initially the program calculated the coefficient from 10%.
I tried to change the accuracy by 2%. The result turned out to be bad - the time for selecting the coefficients was greatly increased.
The question is:
Can other methods be used to speed up the finding of the result. And how fast can the program work?
Maybe someone already faced a similar problem?
Below is the code of the program
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Flerov.PortfolioOptimizer
{
class Program
{
[STAThread]
static void Main(string[] args)
{
var dlg = new OpenFileDialog();
if (dlg.ShowDialog() != DialogResult.OK)
return;
var input = File.ReadAllLines(dlg.FileName).Skip(2).Select(line =>
{
var res = line.Split(';');
var date = DateTime.ParseExact(res[0], "dd.MM.yyyy", (IFormatProvider)CultureInfo.InvariantCulture);
var data = res.Skip(1).Select(decimal.Parse).ToArray();
return new Tuple<DateTime, decimal[]>(date, data);
}).ToArray();
var count = input.First().Item2.Length;
var allKkoefs = new List<decimal>();
for (decimal i = 0; i <= 1; i += 0.02m)
{
allKkoefs.Add(i);
}
var listResult = new List<Tuple<decimal[], decimal>>();
var permutation = allKkoefs.Permutations(count).Select(p => p.ToArray()).Where(p => p.Sum() == 1).ToArray();
foreach (var k in permutation)
{
var koefs = k.ToArray();
var sum = input.Select(p => p.Item2.Zip(koefs, (arg1, arg2) => arg1*arg2).Sum()).ToArray();
var avg = sum.Average();
var std = sum.StandardDeviation(avg);
if (std == 0) std = 1;
var res = (decimal) (avg/std);
listResult.Add(new Tuple<decimal[], decimal>(koefs, res));
}
var best = listResult.OrderByDescending(p => p.Item2).Take(30).ToArray();
var header = "value;";
for (int i = 1; i <= count; i++)
{
header += "koef" + i + ";";
}
File.WriteAllLines(dlg.FileName + ".result.csv", new[]{header});
File.AppendAllLines(dlg.FileName + ".result.csv", best.Select(i => string.Format("{0};{1}", i.Item2,
i.Item1.Aggregate("", (s, arg2) => s+arg2+";"))));
}
}
static class Helper
{
public static decimal StandardDeviation(this ICollection<decimal> num, decimal? avg)
{
if (num.Count == 1)
return num.First();
if (avg == null)
avg = num.Average();
var sumOfSqrs = num.Sum(t => Math.Pow((double)(t - avg.Value), 2));
var n = num.Count;
return (decimal)Math.Sqrt(sumOfSqrs / (n - 1));
}
public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> pool, int selectionSize)
{
var idxs = new int[selectionSize];
var pl = pool.ToArray();
var length = pl.Length;
do
{
yield return GetItems(pl, idxs, selectionSize);
GetNextPermutation(idxs, selectionSize, length);
} while (idxs[0] < length);
}
private static void GetNextPermutation(IList<int> idxs, int selectionSize, int poolSize)
{
var position = selectionSize - 1;
idxs[position]++;
while (idxs[position] == poolSize && position > 0)
{
idxs[position - 1]++;
for (var i = position; i < selectionSize; i++)
idxs[i] = 0;
position--;
}
}
private static IEnumerable<T> GetItems<T>(IList<T> items, IList<int> idxs, int length)
{
for (var i = 0; i < length; i++)
yield return items[idxs[i]];
}
}
}
|
|
|
|
|
This program here plays a small question game over the network, it's multi-threading and is of course based on a server and a client. It's written in C# using windows forms for the client and just console for the server.
I have a problem when the client writes to the server when the user press on enter. On line 70 I try to write to the server but it seems that the connection is somehow closed before I do so because I get the following error:
System.IOEndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.ReadByte()
at System.IO.BinaryReader.7BitEncodedInt()
at System.IO.BinaryReader.ReadString()
at question_game_client.Form1.RunCLient() in somepath:line 112
When I press enter in the textbox it's supposed to write to the server and it does but it does it twice and the client crashes with the error above.
Client:
using System;
using System;
using System.Windows.Forms;
using System.Threading;
using System.Net.Sockets;
using System.IO;
namespace question_game_client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private NetworkStream output;
private BinaryWriter writer;
private BinaryReader reader;
private Thread readThread;
private string message = "";
private void Form1_Load(object sender, EventArgs e)
{
readThread = new Thread(new ThreadStart(RunClient));
readThread.Start();
}
private void Form1_FormClosing(object sender,
FormClosingEventArgs e)
{
}
private delegate void DisplayDelegate(string message);
private void DisplayMessage(string message)
{
if (displayTextBox.InvokeRequired)
{
Invoke(new DisplayDelegate(DisplayMessage),
new object[] { message });
}
else
displayTextBox.Text += message;
}
private delegate void DisableInputDelegate(bool value);
private void inputTextBox_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter && inputTextBox.ReadOnly == false)
{
writer.Write(inputTextBox.Text);
inputTextBox.Clear();
}
}
catch (SocketException)
{
displayTextBox.Text += "\nError writing object";
}
}
public void RunClient()
{
TcpClient client;
try
{
client = new TcpClient();
client.Connect("127.0.0.1", 8190);
output = client.GetStream();
writer = new BinaryWriter(output);
reader = new BinaryReader(output);
do
{
try
{
DisplayMessage("\r\n" + message);
message = reader.ReadString();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
} while (message != "SERVER>>> TERMINATE");
writer.Close();
reader.Close();
output.Close();
client.Close();
}
catch (Exception error)
{
MessageBox.Show(error.ToString(), "Connection Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void inputTextBox_TextChanged(object sender, EventArgs e)
{
}
}
}
Server:
using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Collections.Generic;
using System.IO;
namespace question_game_server
{
class Program
{
private Socket connection;
private int port = 8190;
private Random rand = new Random();
string message = null;
string answer = null;
static void Main(string[] args)
{
new Program().Run();
}
void Run()
{
new Thread(RunServer).Start();
getquestions();
}
public void RunServer()
{
Thread readThread;
bool done = false;
TcpListener listener;
try
{
listener = new TcpListener(IPAddress.Any, port);
listener.Start();
Console.WriteLine("Waiting for connection ...");
while (!done)
{
connection = listener.AcceptSocket();
readThread = new Thread(GetMessages);
readThread.Start();
}
}
catch (Exception)
{
Console.WriteLine("Port " + port + " may be busy. Try another.");
}
}
public string getquestions()
{
int countquestions;
int random_question_val;
try
{
using (StreamReader sr = new StreamReader("questions_and_answers.txt"))
{
String line = sr.ReadToEnd();
string[] questions_and_answers = line.Split(';');
countquestions = questions_and_answers.Length-1;
random_question_val = rand.Next(0, (countquestions));
Console.WriteLine(random_question_val);
string[] question_and_answer = questions_and_answers[random_question_val].Split(':');
Console.WriteLine("Answer:"+question_and_answer[1]);
answer = question_and_answer[1];
sr.Close();
return question_and_answer[0];
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
return null;
}
}
public void GetMessages()
{
Socket socket = connection;
NetworkStream socketStream = null;
BinaryWriter writer = null;
BinaryReader reader = null;
try
{
socketStream = new NetworkStream(socket);
reader = new BinaryReader(socketStream);
writer = new BinaryWriter(socketStream);
Console.WriteLine("Connection successful.\n");
writer.Write(getquestions());
message = reader.ReadString();
Console.WriteLine(message);
if (answer == message)
{
writer.Write("Correct Answer!");
Console.WriteLine(message);
}
if (answer != message && message != null)
{
Console.WriteLine(message);
writer.Write("Wrong Answer!");
}
}
catch (Exception error)
{
Console.WriteLine(error.ToString());
}
finally
{
reader.Close();
writer.Close();
socketStream.Close();
socket.Close();
}
Console.ReadKey();
}
}
}
I guess it has a very simple explanation, I just can't see it. The only thing I know that this happens when I try to write to the server and the program is complaining about some reading issues. So what's wrong?
[edit]Code block added - OriginalGriff[/edit]
modified 8-May-17 3:38am.
|
|
|
|
|
Edit your post and put the code between code tags, like so: (This preserves the formatting.) Also, just include the portion of the code that is giving the problem. Nobody is going to wade through tons of code.
if (answer != message && message != null)
{
Console.WriteLine(message);
writer.Write("Wrong Answer!");
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I converted you code to code block, as Richard suggested - but I'm not looking at that lot of uncommented code trying to work out what you might have done or why!
Help us to help you: edit your post and show us just the relevant code fragments, tell us which line it occurs on, and explain what you have tried to find and find the problem. Remember, we can't run your code here under the same circumstances you do as we have no idea what you are doing - so you need to give us the relevant info (without being lazy and dumping everything on us).
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi
I have
selling point
i want Create Dynamic buttons win app c#
with my table Items database sql server2008 R2
and Get value GUID win I click in buttons
|
|
|
|
|
And what have you tried to do to achieve that?
|
|
|
|
|
Share what you have tried and what issue you are facing on this...
modified 20-Sep-20 21:01pm.
|
|
|
|
|
How I can put selling buttons in my interface to put in them my materials
private void DisplayData5()
{
con.Open();
DataTable dt5 = new DataTable();
adapt = new SqlDataAdapter("select * from MER where GUID = '" + listBox1.SelectedValue.ToString() + "' order by NUBER ", con);
adapt.Fill(dt5);
listBox2.DataSource = dt5;
listBox2.DisplayMember = "NAME";
listBox2.ValueMember = "GUID1";
con.Close();
}
// insert materials
private void listBox2_MouseClick(object sender, MouseEventArgs e)
{
try
{
con.Open();
SqlCommand cmd3 = new SqlCommand(" insert into SellingPoint (GUID, MONY,MONY1,NAME,NUBER,COUNT) select GUID1,MONY,MONY1,NAME,'" + txt_Number.Text + "', '" + textBox2.Text + "' from MER where GUID1 = '" + listBox2.SelectedValue + "' ", con);
cmd3.ExecuteNonQuery();
con.Close();
sum();
textBox7.Text = textBox4.Text;
DisplayData();
number();
textBox2.Text = "1";
}
catch
{
MessageBox.Show("77");
con.Close();
}
}
|
|
|
|
|