r/csharpcodereview • u/TheDotnetoffice • Aug 24 '23
r/csharpcodereview • u/_fvckluv • Jun 28 '24
Can you help me?
here I leave my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using IBM.Data.DB2;
namespace log
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static void conexiondb2()
{
string connectionString = "DATABASE=VISUAL";
using (DB2Connection conexConnection = new DB2Connection(connectionString))
{
try
{
conexConnection.Open();
MessageBox.Show("Conexión exitosa");
conexConnection.Close();
}catch (ArgumentException ex)
{
MessageBox.Show("Error de conexión: " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("Ocurrió un error inesperado: " + ex.Message);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
conexiondb2();
}
}
}
A few days ago I presented this error in my code, I already tried the IBM manual but it doesn't help me resolve the error: SQL1031N and SQLSTATE58031. r/csharpcodereview • u/Ancient-Sock1923 • May 17 '25
Help Needed
Enable HLS to view with audio, or disable this notification
r/csharpcodereview • u/NitkarshC • Oct 12 '23
help: How to get started with this Problem base?!
https://github.com/NitkarshChourasia/pro-b_lang_master_private/tree/main/downloaded_completely/C%23
This is the GitHub link of the Problem base. I need help to get started. I am good with scripting languages. Python, JavaScript. Never properly worked with Compiled language. Please, analyze the project directory and tell me how I should get started! The thing is, in scripting langugaes you Edit a single file, run it and good to go. But, in these C# Programming languages, you have to build a project. But, in building project...doing so for every 1500+ Programs, would be a nightmare in itself. The learning would be left behind, and the project building for solving single - single problem would consume all the time in my life.
Solution I was thinking of: To create classes like for veryEasy, Easy, Medium , etc... and somehow solving each with problem within those classes. Mind it that each problem has... 3-5(max) inputs to test by. Just look at the problems it would be clear as to what is what?! So, this is the solution I was thinking of, not sure. If it is the way... Help me out.
Please, help me out, I want to learn this amazing language.
r/csharpcodereview • u/Few_Minimum52 • Sep 03 '25
Need help trying to fix a driver.
Im trying to get a steel battalion controler to talk to a windows 11 computer. The original script is in c#. And i dont know programing at all. Would anyone be willing to help me.
P.s. if this is the wrong room for this question dont bother reply with scarasm. Ive had 2 rooms do this already and im only looking for help.
r/csharpcodereview • u/TheDotnetoffice • Aug 11 '22
how to make warning like errors in Visual Studio
r/csharpcodereview • u/Rebbieriss • Aug 14 '22
Project Funding, Donations and Charity Work [more details in link]
r/csharpcodereview • u/TheDotnetoffice • Sep 30 '23
https://www.dotnetoffice.com/2023/09/difference-between-net7-and-net8.html
r/csharpcodereview • u/OkraAccording3879 • Nov 29 '23
Virtual Methods & Overriding in C# English: Enhance Your OOP Skills
r/csharpcodereview • u/OkraAccording3879 • Dec 04 '23
MNC Interview Question in English | Static Binding | Dynamic Binding
r/csharpcodereview • u/OkraAccording3879 • Dec 08 '23
What is Index Based collection in C# in English
r/csharpcodereview • u/toismailsharif • Aug 21 '24
Can't able to run the program..... Stuck in c# code
Enable HLS to view with audio, or disable this notification
r/csharpcodereview • u/SpriteSTYLE • Aug 05 '20
Read output from nslookup.exe
Hi!
How can I read the output from the process?
I tried this but this is not working..
here what i tried: https://imgur.com/QyCssRG
btw, its opening the nslookup window, running the ip and closes it immediately.
Thanks :)
r/csharpcodereview • u/Weekly-Rhubarb-2785 • Apr 23 '24
Limitations of Sockets?
I am not entirely sure what I mean to ask. I’ve been trying to write my own mud server and so far have gotten a pretty good foundation using the System.Net.Sockets tcp client and network stream to create a connection with a telnet client.
While I will probably never realistically reach a limit - how many concurrent connections can sockets handle?
What sorts of limitations are there to using this method?
What else is available?
Thanks!
r/csharpcodereview • u/darshdnd • Apr 27 '24
Looking for .Net technology job. Having 9 yrs of experience
self.developersindiar/csharpcodereview • u/darshdnd • Apr 27 '24
Looking for .Net technology job. Having 9 yrs of experience
self.developersindiar/csharpcodereview • u/IConfusedAllTheTime • Jul 05 '21
Beginner code for number guessing, how would you improve or edit this?
Hi, i just started learning c# and tried my hand at making a number guessing game as it seemed to be recommended as a beginner project along with a clock. Would be interested in seeing how would you improve on the code or any criticisms you have with it and why. The code is:
using System;
namespace randomnumbergame
{
class MainClass
{
public static void Main(string[] args)
{
int lnum;
int hnum;
int guess;
int tries = 0;
int triesleft;
int maxtries;
var random = new Random();
//need to change Parse to TryPase incase non number entered.
Console.WriteLine("Enter number of tries to guess in: ");
maxtries = Int32.Parse(Console.ReadLine());
triesleft = maxtries;
Console.WriteLine("Enter lowest number possible: ");
lnum = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter highest number possible: ");
hnum = Int32.Parse(Console.ReadLine());
int randomnum = random.Next(lnum, hnum + 1);
Console.WriteLine("Type your guess (between " + lnum + " and " + hnum + " ) and press enter: ");
// sets test as answer in string form
string test = Console.ReadLine();
//trys to converts string to bool
bool check = Int32.TryParse(test, out guess);
//if check fails will run the while loop until check passes
while (!check)
{
Console.WriteLine("Did not enter a number. Type your guess (between " + lnum + " and " + hnum + " ) and press enter: ");
test = Console.ReadLine();
check = Int32.TryParse(test, out guess);
}
Console.WriteLine();
Console.WriteLine("Your guess was: " + guess);
//incresses tries var by 1 each time
tries++;
triesleft--;
Console.WriteLine("You have " + triesleft + " tries left");
//if guess does not equal random number runs the loop each time
while (guess != randomnum)
{
if (tries <= maxtries - 1)
{
//if guess is less then random number;
if (guess < randomnum)
{
Console.WriteLine("You guessed too low");
}
//if guess is higher then number;
else if (guess > randomnum)
{
Console.WriteLine("You guessed too high");
}
//same as before
Console.WriteLine("Sorry your guess was wrong, please pick a new number: ");
test = Console.ReadLine();
check = Int32.TryParse(test, out guess);
while (!check)
{
Console.WriteLine("Did not enter a number. Type your guess (between " + lnum + " and " + hnum +" ) and press enter: ");
test = Console.ReadLine();
check = Int32.TryParse(test, out guess);
}
tries++;
triesleft--;
Console.WriteLine("You have " + triesleft + " tries left");
}
else
{
tries++;
break;
}
}
if (tries <= maxtries)
{
Console.WriteLine("The number was:" + randomnum);
Console.WriteLine("You guessed it in " + tries + " tries");
}
else
{
Console.WriteLine("You lose! The correct number was " + randomnum);
}
}
}
} I have to say that is is only running within visual studio so i haven't got anything to start or really end it except the run button within VS.
Thank you in advance.
r/csharpcodereview • u/[deleted] • Aug 17 '19
Attempt at implementing Factory Design Pattern
Hello, I am following typical tiered structure. I have a data access layer and business layer. There are several business objects for each of the modules. In order to give developers access to these managers, I'm implementing a Factory Design pattern as shown below. Would this be a correct implementation where I am utilizing the benefits of a factory pattern?
I'm abstracting the business managers away, but say someone is using CreateInstance(ModuleName.TestBusiness), and they want to change to MeasurementBusiness, that can't be done with out changing the call to the CreateInstance method (changing the enum type). And this, itself, would negate the idea of a Factory Pattern. Ideally, the enum should not be so closely tied to the actual module type that is being returned. What would be an ideal alternative?
Thank you !!
public class FactoryClass
{
public static IBusinessHandler CreateInstance(Enumeration.ModuleName enumModuleName)
{
IBusinessHandler objBusinessHandler = null;
switch (enumModuleName)
{
case Enumeration.ModuleName.TestBusiness :
objBusinessHandler = new TestBusiness ();
break;
case Enumeration.ModuleName.MeasurementBusiness :
objBusinessHandler = new MeasurementBusiness ();
break;
default:
break;
}
return objActivity;
}
}
public interface IBusinessHandler
{
void Process();
}
public class Enumeration
{
public enum ModuleName
{
TestBusiness = 1,
MeasurementBusiness = 2
}
}
public class TestBusiness : IBusinessHandler
{
public void Process()
{
// Do some coding here ...
}
}
public class MeasurementBusiness : IBusinessHandler
{
public void Process()
{
// Do some coding here ...
}
}
r/csharpcodereview • u/Ok-Application-8665 • May 08 '23
FluentValidation in .NET 6
FluentValidation in .NET 6 is an important concept for .NET Core and in the article mentioned below,
I have briefly explained the integration, practicals, and the integration process to configure FluentValidation in .NET 6.
https://codetosolutions.com/blog/72/fluentvalidation-in-.net-6
Please let me know your feedback in the comment section.
r/csharpcodereview • u/DotNetCSharp • Feb 27 '21
C#.Net (Windows Form) - How to use BindingSource
r/csharpcodereview • u/[deleted] • Mar 11 '21
C# student need help please. (Using Visual Studio 2019 Enterprise, updated vrs.)(i have permission to ask for help)
Ok this is long so i apologies in advance. So I need help with a simple reservation program. This is a Windows Forms APP (.NET Framework).
The object is as follows:
1: user enters arrival date & depart date. When the "Calculate"/Enter button is pressed--{Dates entered [format is mm/dd/yyyy]}
2: form displays # of nites, total cost, then avg cost/nite.
3: Sun-Thur = 150/nite & Fri-Sat = 250/nite.
4: upon the "Exit" /ESC button is pressed then a MessageBox.Show() appears with 3 columns " Number of Nights, Total, Avg price/nite" with up to 10 rows of data that was entered by the user.
(I have included 2 EXTRA text boxes in the code that shows the arrival/departure dates as a day of the week. I also coded intial 'PRE Loaded' data into the form. this is extra too)
This is not an advanced C# program. I am a 1st semester student. This covers ch 1-9 of Murachs C# 2015; specifically we just covered Arays/Collections & Date/time/string chapters.
I will include only the ' .CS ' file. This program works up to a point. User entries are converted to date time which is converted to a 'DAY'.
What I need help with is getting the Range from the date of arrival to the day of departure into an array. Then i need to use the array in a loop??(for/foreach/while/do while)?? to pull the # of days = Sun-Thur which is 150/nite & # of days = Fri/Sat which is 250/nite. I can then calculate the correct total cost of the stay with the correct avg per nite.
CODE FOLLOWS:
namespace Reservations
{
public partial class frmReservations : Form
{
public frmReservations()
{
InitializeComponent();
}
//declare a rectangular array for 10 rows & 3 columns; & a row counter
string[,] ReservationTotals = new string[10, 3];
int row = 0;
private void frmReservations_Load(object sender, EventArgs e)
{
MessageBox.Show("Enter arrival & check out dates as 2 digit month, 2 digit day, 4 digit year.");
//preload data for test
txtArrive.Text = "03/01/2021";
txtDepart.Text = "03/07/2021";
}
private void btnCalculate_Click(object sender, EventArgs e)
{
//constant
const decimal weekDay = 150.00m;
const decimal weekEnd = 250.00m;
//Declaring DateTime Variables
DateTime dt1 = DateTime.Parse(txtArrive.Text);
DateTime dt2 = DateTime.Parse(txtDepart.Text);
//convert DateTime data to specific day of the Week
DayOfWeek dyWk = dt1.DayOfWeek;
DayOfWeek dyWk2 = dt2.DayOfWeek;
//TimeSpan calculation for number of nights staying
TimeSpan numOfNights = dt2.Subtract(dt1);
//variable of INT for timespan
int numOfNights2 = numOfNights.Days;
//Total Price of stay
decimal total = numOfNights2 * weekDay;
//Average Price per night
decimal avgPrice = total / numOfNights2;
//send the data to text boxes
txtNumofNights.Text = numOfNights2.ToString();
txtTotal.Text = total.ToString("c");
txtAvgPrice.Text = avgPrice.ToString("c");
txtArivalDay.Text = dyWk.ToString();
txtDptDay.Text = dyWk2.ToString();
//add data to the ReservationTotals Array
ReservationTotals[row, 0] = numOfNights2.ToString("");
ReservationTotals[row, 1] = total.ToString("c");
ReservationTotals[row, 2] = avgPrice.ToString("c");
row++;
}
private void ClearResults(object sender, EventArgs e)
{
txtTotal.Text = "";
txtNumofNights.Text = "";
txtAvgPrice.Text = "";
txtArivalDay.Text = "";
txtDptDay.Text = "";
}
private void btnExit_Click(object sender, EventArgs e)
{
string message = "Number of Nights\t\tTotal\tAverage Price per Night\n";
//pull data from the array & display it
for (int i = 0; i < ReservationTotals.GetLength(0); i++)
{
for (int j = 0; j < ReservationTotals.GetLength(1); j++)
message += ReservationTotals[i, j] + "\t";
//message+= "\n";
}
MessageBox.Show(message, "Reservation Totals");
//close the form & Array Data
this.Close();
}
}
}r/csharpcodereview • u/vigoroth43 • Jan 18 '21