Most voted "c#" questions
This tag should be used when the question refers to some resource, information or problem related to the C#language. C# ("C Sharp") is a multi-paradigm programming language that has strongly typed variables, is imperative, declarative, functional, generic, object-oriented and component-oriented, which are designed to be executed in . NET Framework.
Learn more…13,899 questions
Sort by count of
-
4
votes2
answers102
viewsProtect Class for namespace c#
I am developing a C# application for Unity 3D where it will manage several types of database (Mysql, Postgress...), the problem is that I have classes that manipulate each type of database within my…
-
4
votes1
answer1477
viewsWhat exactly does the Application.Doevents() method do?
According to the help of Microsoft, the method Application.Doevents(): Processes all Windows messages that are currently in the message queue. But what does that mean? Why does he say messages? What…
-
4
votes1
answer436
viewsHow to shuffle string list in c#?
I have a console application, in which there is a list: List <string> ListaFrases = new List<string>(); This list is built through user inputs in the console. How to display your…
-
4
votes2
answers872
viewsWhat are anonymous methods and what is their main purpose?
I know they’re used to working together with delegates, but the sources I found were a little confused in my opinion.
-
4
votes1
answer53
viewsComboboxes that share the same Datasource, swap the selection together
I am doing a production order project and I have 7 combobox picking the values from the same table (which are the raw materials). I’m using this code on load form to load the combobox:…
-
4
votes2
answers624
viewsWhen using optional parameters above overloading and vice versa?
An optional parameter in C# is declared as follows (see parameter y): public void DoFoo(String x, String y = "") { ... } In many cases, this Feature can be replaced by Overload signature of the…
-
4
votes2
answers455
viewsHow to fix this error "Cannot Convert from 'int' to 'char[]'
Why is this error presented? I believe the logic is right.…
-
4
votes4
answers447
viewsC# Textbox to stop receiving after comma
I need a textbox to stop receiving values after the comma, once it reaches 2 houses. To simplify, think that the text has limit after the comma, but none before it. Example: Type the number 2.99.…
-
4
votes3
answers1011
viewsHow to compare strings differentiating case from case?
I have following code: Usuarios user = DataModel.Usuarios.Where(x => x.Login.Equals(login,StringComparison.OrdinalIgnoreCase) &&…
-
4
votes1
answer416
viewsHow to copy text from one text file to another
I wanted to copy the text from one text file to another with a different name and add a - at the beginning of the line of the text file. For example: I have a text file with the following text…
c#asked 6 years, 11 months ago Pedro Azevedo 435 -
4
votes1
answer100
viewsTextboxfor returned Null Post
I have a form where I query an API using jquery. The query returns the data and fills the textboxfor with this data : $.getJSON("//viacep.com.br/ws/" + cep + "/json/?callback=?", function (dados) {…
-
4
votes2
answers92
views -
4
votes1
answer133
viewsError converting bitmap to pictureBox on C#?
I’m creating a path within C# to always be able to call images from this path, (using namespace.Properties) and through it I am able to call the Resources and using the following code : var myIcon =…
-
4
votes1
answer103
viewsDatabase maintenance c#
I have a system in another language and I need to create an update for this system, but it needs to be run Mysql Scripts for database maintenance. I searched in Java and found Maven that has all…
-
4
votes1
answer325
viewsMethods with Dynamic C#parameter
I need your help with the following question. I have a data access class that has a method that takes the parameters to run a stored database. The problem is this, I have several objects in the…
-
4
votes4
answers1102
viewsHow to show data from 2 tables in a grid?
I am developing an application using Windows Forms and I wanted to be able to show the data of 2 tables in a gGrid, by SQL command I can do this SELECT SU.SUBCATEGORIAID, SU.NOME, SU.CATEGORIAID,…
-
4
votes2
answers170
viewsDoubt - Savechanges does not work, only returns 0
Follows code: using (var db = new Entities()) { var result = db. Tabela1 .Where(x => x.Id == 1) .Select(x => new SuaClasse { Coluna1 = x.Coluna1, }) .FirstOrDefault(); if (result.Coluna1 !=…
c#asked 6 years, 11 months ago Matheus Miranda 5,375 -
4
votes3
answers932
viewsError comparing numbers and checking if they are equal
I’m doing a simple C# exercise in which I have to receive two numbers, compare them and print out which is the largest or whether they are equal. When I start the program, I can only put the first…
-
4
votes1
answer329
viewsHow to filter an array within a Collection in MONGODB - C#
I have the Collection PESSOA with a list of Languages as below: { "_id" : ObjectId("576be476ab76191bec2ff38c"), "Nome" : "Nome um", "Idiomas" : [ { "idioma" : "pt-BR", "descricao" : "Brasil" }, {…
-
4
votes1
answer263
viewsPassing model via dynamic form parameter in . NET MVC
I created this function to generate a handle (or slug, how to prefer) for the model users, the problem is that I would like to make it more "modular", so that I can easily implement in any other…
-
4
votes1
answer532
viewsHow to get the hostname of the client using c#?
I need to save in which machine the user performed certain action, for this I was using the following excerpt: string maquina = Dns.GetHostName(); However, little did I know that this returns me the…
-
4
votes3
answers763
viewsI need to validate a TXT layout in C#
I have a TXT file where I need to validate the number of characters of each column according to the layout of each document. Note: Documents are all in one file *.txt In the second column is the…
-
4
votes2
answers91
viewsChecking whether data persisted successfully
What would be the best way to get one bool indicating whether the method Add() and then SaveChanges() was successfully performed? Am I trying like this? Is that right? public bool…
-
4
votes1
answer421
viewsUser Control C#
I have the following user control that is being used in a Form: public partial class CampoTelefone : UserControl { private void maskedTextBoxTelefone_Validating(object sender, CancelEventArgs e) {…
-
4
votes2
answers2610
viewsDate and time validation
How do I make so that in the date field, is not saved a date that has already passed, for example yesterday and in the time field is not typed an invalid time, for example 27:00, only the Brazilian…
-
4
votes2
answers494
viewsHow to store an array in a string?
Example: string x; string[] y = {"5", "0","0","5","5"}; x = "50055" I want to put it all together into one variable. I will store in a variable not print.
-
4
votes1
answer5565
viewsHow to remove an item at an array position?
Example: string[] x = {"3","2","1"}; I just want to take off the item "2" array x, resulting in: x = {"3","1"};…
-
4
votes1
answer150
viewsDoes Xamarin generate Java source code?
I read that with Xamarin it is possible to program in C# for example, and generate a native application Android and IOS. After programming in C#, does it generate sources in Java? I can after making…
-
4
votes1
answer331
viewsRight Way to Make Relationship One To Many Using C# and Mongodb
I have two entities, Sistema and Comentario where a system can have several comments: public class Sistema { public ObjectId Id { get; set; } [BsonElement("SistemaId")] public int SistemaId { get;…
-
4
votes1
answer95
viewsString Contains Empty returns true
Why when using the Contains("") in a string not empty returns true? Example if ("MinhaString".Contains("")) { Console.WriteLine("String contém vazio"); }…
-
4
votes1
answer299
viewsHow to take a column in the database, perform a calculation and send it to the grid
I want to perform a calculation using the value of the VAL_VIDA_UTIL field of my BD and then save the result since calculation in a new variable VAL_DEPRECIACAO and pass to my fieldName, but I’m not…
c# sql-server webforms ado.net devexpress-asp.net-ajaxasked 8 years, 2 months ago Fernanda Ferreira 197 -
4
votes1
answer1580
viewsHow to Set Up Multiple Web API Get
I need to provide in my web api three forms of query: First Get with all "Getall" records, the second GET by id and a third GET with ribbon options, sent by client, e.g.: Name contains the letter…
-
4
votes3
answers857
viewsDollar next to number in Tostring format
When I try to format a value using .ToString("c2") do . NET the symbol of the coin comes stuck with the number. This makes the formatting ugly and wrong to my point of view. Example:…
-
4
votes2
answers123
viewsProblem creating user class (Identityuser) relationship using Identityframework
When I create any relationship with my user class: namespace Modelo.Cadastro { public class Usuario : IdentityUser { [StringLength(250, ErrorMessage = "O nome de usuário deve conter no mínimo 3…
c# asp.net-mvc entity-framework asp.net-identityasked 8 years, 2 months ago Luiz Henrique da Fonseca 41 -
4
votes1
answer192
viewsParallel Processing Routine C#
I would like to start a data processing method whenever I receive a String with START content through the Transceiver event.Receivelineeventhandler(); but this method will have a processing time as…
-
4
votes2
answers842
viewsUsing Array.Foreach to modify the collection
I want to remove spaces from the beginning and end of the string (Trim) in all positions of array, but none of the ways below worked. What am I doing wrong? var optionArray = new string[] { "in the…
-
4
votes3
answers162
viewsProblems with SELECT with 2 Wheres
I’m having a bit of an amateur problem here. I’m not getting this SELECT from 2 CONDITIONS, and I can’t find the ERROR! Someone please give me a light there! Follows the Code: OleDbConnection Con =…
-
4
votes2
answers310
viewsWhich object performs best? Sqldatasource or Datatable?
In terms of performance, speed, or even safety, what is the best object to be used as a DataSource? Example, I’m creating a DataSource, to popular a GridView: For SqlDataSource:…
-
4
votes2
answers358
viewsKeep variable in memory until system reboot
There is a way to keep a variable in the memory of the machine until it restarts? My application made a change in the system and sent the message to the user to restart the machine, to prevent any…
-
4
votes2
answers501
viewsHow do I determine the search path for Controllers and Views?
I’m studying ASP.NET Core MVC on a macOS. When I create a new project, the IDE automatically arrow my Views into a folder called "Home". If I change the name of that folder or change the folder…
-
4
votes2
answers489
viewsASP.NET Core Isdevelopment
When creating a project with the dotnet cli dotnet new Razor -o Razorpagescontacts How do I change the environment variable to developer mode when running the application using dotnet run. Since in…
-
4
votes1
answer1351
viewsHow to discover the file extension through the Bytes array?
I wonder if it is possible to get a get on the file extension through the Byte Array. Because I download a file from the server, and it can be both . JPEG and . EPS, however I am not able to know…
-
4
votes2
answers621
viewsEntityframework . Asenumerable() or . Tolist()?
In one of the projects I picked up I saw the following code, which implements a data listing method of a given entity, but this listing is used only for reading: /// <summary> /// Listar todas…
-
4
votes1
answer167
viewsProblem returning items in a Relationship in the Entity Framework
Talk Personal All right!? I’m going through the following problem in the Entity framework that I think is some mistake I’m making when it comes to relating two classes: I have a Class called:…
-
4
votes1
answer84
viewsHow to control migrations in two distinct contexts?
I have two contexts and I would like to know how to activate each of them. For example Add-Migration Contexto 1, Add-Migration 2 How can I add new ones Migrations for each context?…
-
4
votes1
answer166
viewsIf I have two servers (application and database) with different time zones, which one is better to use as a base?
I am working with the Mysql server of a hosting, I can not change the time zone of the same, I mean it uses the "Mountain Standard time (MST)", on the other hand, I am using the ASP.NET server and I…
-
4
votes1
answer1670
viewsHow to implement methods and classes by some keyboard shortcut in visual studio?
I need to implement methods and classes "keyboard" to get a value automatically. 1: Implement UI methods in the Home class: class Inicio : Interface { } 2: Set and Get automatically: private static…
-
4
votes2
answers3931
viewsCreate dll in C# and use in Delphi 7
I need to create a dll in C# so I can use it in Delphi. I tried the following: I created a basic dll with a sum method, but when calling it in Delphi does not return anything, it would be like the…
-
4
votes2
answers184
viewsHow to use the IN clause in Lambda?
A doubt arose that I thought would be easy, but the content I found could not understand. Well, here’s the thing: I have the tables "Client" and "Errosproducao_client" where they relate form 1 to N,…
-
4
votes3
answers973
viewsWebsocket - c# . NET
I found almost nothing about Websockets + . NET on google, I would like to know how this server is made using the . NET in the future the idea is to create an application and hardware (Arduino) that…