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
-
3
votes1
answer492
viewsCreating Models that derive Identityuser or use the Aspnetusers table
I am developing management software for my gym. I have Students, Teachers and system users. I installed the Identity. I created a model calling for Aluno who inherits from the IdentityUser public…
c# asp.net-mvc entity-framework modeling asp.net-identityasked 8 years, 1 month ago Dorathoto 7,426 -
3
votes1
answer455
viewsPass Datatime javascript to ASP.NET MVC Controller by Ajax
I’m having trouble passing date of javascript to the Controller via ajax.. Model: public class ModelA{ .... [Required] DataType(DataType.Date)] DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]…
-
3
votes3
answers676
viewsDatatables highlight line with higher percentage
In my system I have a table mounted by DataTables. Data is received from the server via Ajax. Example of the data structure loaded in the table: DDD | Processed | Approved | Percentage | 11 - 19 |…
-
3
votes1
answer2206
viewsMath.Round method does not round correctly
I’m having trouble with the method Math.Round() in C#, some values that it does not round correctly, I will give some examples: Math.Round(1190.245, 2) 1190.245 he should round to 1190.25 since it…
-
3
votes1
answer142
viewsHow to place a Readonly column?
I’m trying to leave only one column of GridView as ReadOnly, I’m doing like this: if (id_crm == 0) { textBox2.Text = Convert.ToString(cod_crm()); DataTable dat_itens = new DataTable();…
-
3
votes1
answer2475
viewsIs there a reliable way to test the internet connection?
I read about the function NetworkInterface.GetIsNetworkAvailable, but it does not work in my case, since I need to check if there is really an internet connection. I also read about trying to access…
-
3
votes1
answer399
viewsAlternative to the Transactionscope
I’m using Entity Framework (version 4.4) in a project Aspnet MVC with .NET Framework a little old (version 4.0) and SQL Server. I do not have access to the server where the application is hosted,…
-
3
votes1
answer84
viewsWhat is the fastest way to build text?
I have a large text (1000 lines) with formatting. Briefly (not this text but I will use an example) I have 2 ways to build it: StringBuilder sb = new StringBuilder(); sb.append("oi" + "meu nome" +…
-
3
votes1
answer148
viewsViewmodel’s communication: return data to previous screen
I have a screen A that has a text field and a button, that screen button A, opens a second screen B. That screen B has another text field to fill and save, when the person click save the screen…
-
3
votes2
answers576
viewsExtract Date from a C#String
I need to extract two dates from a string that comes in the following format: string teste = "Aprovados por autorizantes da aplicação -> 02/03/2018 à > 02/03/2019"; This is the start date and…
-
3
votes1
answer793
viewsSplit in single quotes '
I have a string where there are simple quotes (') and would like to make a split but by putting, ''');, he breaks the code. splitString = splitLines[i].Split(' ', ',', ';', '"', '(', ')', '!', '?',…
c#asked 6 years, 7 months ago Thiago Mohr da Silveira 33 -
3
votes2
answers198
viewsBhaskara beginner
When I compile this code, it appears: a1 vale NaN(Não é um número) and then: a2 vale NaN(Não é um número), follows the code: private void button1_Click(object sender, EventArgs e) { int a = 2; int b…
c#asked 6 years, 7 months ago Antonio Matheus 31 -
3
votes0
answers284
viewsUsing JOIN with HQL function in Nhibernate?
I am trying to run a JOIN using HQL with Nhibernate and returns an empty list. How to do this ? I’m trying like this. [Serializable] public class Cliente { public virtual int id { set; get; } public…
-
3
votes0
answers132
viewsError generating Migrations Entitycore for Mysql
Following guys I’m trying to use the new Efcore being that with Mysql, I installed the following packages nuget: Install-Package Mysql.Data.Entityframeworkcore -Pre Install-Package…
-
3
votes1
answer590
viewsHow to apply 2 mascara to the same textbox windows form c#
I’m with 2 checkbox natural person and legal person, and only one textbox. I want to select on checkbox individual, I want to apply the mask to CPF, or when selecting the legal person he applies the…
-
3
votes1
answer1240
viewsHow to call and display a WPF Window that is in a dll
I have a DLL containing a WPF window, created through a project of the type WPF User Control Library. How do I display this window from another project? XAML window (DLL project): <Window…
-
3
votes1
answer113
viewsError, Loop when pressing ENTER with e.Keycode
I’m trying this code: private void txtEmgSearch_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.btnEmgSearch.PerformClick(); } } The command itself works normally, but…
-
3
votes1
answer101
viewsSend email without it appearing in the mailbox
I don’t want those items sent in the real estate email. string emailOrigem = imobiliaria.Email; string password = imobiliaria.Senha; string html = getBody(dados); //aqui serve pra formata o html if…
-
3
votes1
answer316
viewsHow to automatically minify CSS/Javascript in ASP.NET MVC5
I use Visual studio 2017, my application runs on ASP.NET MVC5 (Razor), there is a way to minify all the files I choose at the time of "Publish" ?
-
3
votes1
answer76
viewsFunction that returns other functions
I have three methods being called separately on controller with JSON. Each one of them returns to me Id Name. I need to call these three methods in the same function in the controller. How can I…
-
3
votes1
answer174
viewsSql Server Stored Procedures
I am starting the development of an application, basically it is a managerial control of companies. The application will issue NFC-e, Nfe, control stock, finance and etc, the database will be hosted…
-
3
votes1
answer438
viewsStoring multiple values of an Enum in the database
I wish I could save several options of an Enum (day of the week) something like 1,3,5 (Monday, Wednesday, Friday) As modeling described here. I created a model public class Horario { [Key] public…
-
3
votes1
answer471
viewsDoubt with Time Asp.net mvc
I have a timer that I am testing and the same returns me an error: An Exception of type 'System.Web.Httpexception' occurred in System.Web.dll but was not handled in user code Additional information:…
-
3
votes2
answers57
viewsInitializing Array from a new class
Considering two classes in C#: public class aClass { public string afield; } public class bClass { public aClass[] bfield; } I plan to start the variable as bClass cVar = new bClass();…
-
3
votes2
answers1011
viewsReturn with 2 C#Values
I want to give return of two values in c#. My code is like this currently, just returning the imagePath, but I want to return the imagePath and the normalPath at the same time. string imagePath =…
-
3
votes2
answers3734
viewsLimit decimal places float c#
I would like to show the mediadesp and mediareceit with 2 decimal places after the comma. private void MediaReceitaseDespesas() { /* ----TOTAL / QTDE DE VALORES INFORMADOS----*/ mediadesp = somadesp…
-
3
votes1
answer269
viewsActionresult or Jsonresult returning Json?
I see many codes in Controller where it is used as a method ActionResult returning Json(), but I also see an approach using the JsonResult logically returning Json. Is there any difference between…
-
3
votes2
answers224
viewsIs it possible to force a method to be called only by a specific one?
I have a father method that calls a son method, I wish the son method could only be called exclusively by the father method, it would be possible? Example: public void MetodoPai(){ //codigo…
-
3
votes1
answer274
viewsWhen consuming an API that returns me serialized data in JSON, how do I know the data types of the properties?
I have no experience with JSON or web services consumption, but I am trying to consume an API that gives me weather data. Here is the documentation of the API I’m trying to consume. This API returns…
-
3
votes4
answers1202
viewsWhat kind of data to use for sale ID
I have a Windows Form application developed in C# and with SQL database. One of the functions of the system is to carry out SALE for several different COMPANIES and in several different POS (point…
-
3
votes1
answer4024
viewsPrint PDF file using Printdocument
I am developing an application, Console Application in Visual Studio 2015, that its function is to print documents. I can print TXT and DOC without problems using the class PrintDocument but I can’t…
-
3
votes2
answers172
viewsserialize class item in textual documents
I would like to take the elements of my products class and record a txt file as would my Serialization method. class Program { static void Main(string[] args) { var products = new…
c#asked 7 years, 11 months ago fernando tso 121 -
3
votes2
answers1159
viewsConvert string to integer
I can’t convert my text TextBox in one piece. namespace Pag98_Exe1 { public partial class frmveiculos : Form { public frmveiculos() { InitializeComponent(); } Veiculos veiculos = new Veiculos();…
-
3
votes1
answer63
viewsWinforms application stops working if computer goes into hibernation
I have an application in winforms, which is on the company server, so I pull the shortcut to the desktop and the collaborator runs normally. The problem started to happen, when we exchanged some…
-
3
votes2
answers74
viewsHow do I stop "for" when I find an item in the list?
I have the following code: Console.Clear(); Console.Write("Nome da moto:"); string nomem = Console.ReadLine(); for (int i = 0; i < ListadeVeiculos.Count; i++) { if (nomem ==…
-
3
votes1
answer75
viewsClaims no Testmethod
Good morning, you guys, I’m starting TDD in Visual Studio, and I’m having problems/difficulties passing Claims permissions on the request that is made to the server. The following error is…
-
3
votes2
answers635
viewsWhy is this code not calculating the average correctly?
I probably have to be really bad at math today to not be able to make a simple code that calculates the average of two values... I just don’t understand what I did wrong... BTW, I hope the average…
-
3
votes1
answer391
viewsValidate data from an object with Dataannotations C# Winforms
Good afternoon, I have the following Entity class marked by Data Annotations: public class Cargo { [Key] [Display(Name ="Código")] public int Codigo { get; set; } [Required(AllowEmptyStrings =false,…
-
3
votes2
answers371
viewsWorking with Seed + FK Method
I’m finding it difficult to work with the method Seed, Because I register the state, and right away I wanted to register the cities, and then I can’t reference the state in the city, what could I…
-
3
votes3
answers72
viewsFilter specific file to not delete
How to make the code not delete a specific file I want between the .exe which I picked up. Example: I want it not to delete "test.exe", but still to continue erasing all the rest. Follows the code:…
-
3
votes1
answer89
viewsHow to refer to the copyright of the Pdfsharp tool under the MIT license?
I need to make a program in C# that generates a PDF report. For this, I am using the Pdfsharp, which is under the MIT license. In this case, where should I put the reference to the Pdfsharp license?…
-
3
votes3
answers944
viewsAdd Text In textbox at a certain position C#
Hello, I am developing a dental software which one of the functions is to select a tooth on a button and add the name of this tooth in a textbox. Until then no problem, but the point is that this…
-
3
votes2
answers111
viewsWhy is the last letter of my code replaced by a question mark "?"?
The teacher asked for a C# code as a term paper that encrypts a text from a file. The code isn’t polished yet or anything, I’m just doing the raw then I’ll add more things, but my problem is that…
-
3
votes1
answer165
viewsDropdownlist in C# with Htmlhelper
I’m new here and also new to the universe ASP.NET. I’m having a hard time creating a DropDownList for a form on a web page with ASP.NET MVC and C#. I made a user registration form and one of the…
-
3
votes4
answers1437
viewsGet user logged in to Asp.Net Core 2.0
How do I get the User who is logged in to the class ? I’m trying this way: public class Teste { private readonly UserManager<Usuario> _userManager; public Teste(UserManager<Usuario>…
-
3
votes2
answers220
viewsInheritance problem
I have a problem with a bank search, I will try to explain in the best possible and clearest way. I have a table Pessoa and a table Cliente, the last inherits from Pessoa, I also have a table…
-
3
votes2
answers1303
viewsWhat is the difference between creating a Context with Dbcontext and Datacontext?
What is the difference between creating a Context with Dbcontext and Datacontext? Is there any difference in performance or best practice between one or the other? See the examples below; namespace…
-
3
votes2
answers1191
viewsDoing operations/handling Datetime
The idea is for the user to type in a textbox to horaEntrada and in another to horaSaida where in the case of these two variables they should have the format "HH:mm" hours and minutes only…
-
3
votes2
answers660
viewsHow to pick a value between brackets in the string?
I have a string that will vary the values, I need to get the values inside the [], {"time_zones":[]} In case it would be empty, it may be filled: {"time_zones":[teste]} I’m trying to do it like this…
-
3
votes2
answers351
viewsprogressbar reaches maximum value but visually does not fill c#
I am working with a software in C#, in which after a login screen, appears a splashscreen with a progressbar that when it reaches its maximum value (100), she calls the main form of the program. The…