Most voted ".net" questions
The Microsoft . NET is a set of libraries and functions that are part of the Basic Class Library (BCL), such as user interface functions, data access, connectivity, cryptography, web development, mathematical algorithms, and network communication.
Learn more…2,689 questions
Sort by count of
-
3
votes2
answers206
viewsWhere to place the View Model rule
I need to create a View Model to use on the screen. I’m wondering where to put the button rule be enabled or not. I thought about this implementation, I would like to know if it is the best way.…
-
3
votes2
answers6439
viewsSerializing and Deserializing Json objects with C#
Consider the JSON below { "atividade_principal": [ { "text": "Atividades de televisão aberta", "code": "60.21-7-00" } ], "data_situacao": "03/11/2005", "nome": "GLOBO COMUNICACAO E PARTICIPACOES…
-
3
votes2
answers5175
viewsCopy a List to another List without dependencies
How do I copy data from one list to another in a way that is independent of each other? I have a list<> of a class I created where the data inserted in it, appear in a listbox, and I wanted to…
-
3
votes2
answers914
viewsTime difference Timespan in 24hrs format
I am asking this question because I have not located any topic with my problem, which is very similar to others. I have 2 fields TimeSpan? one of which relates to check-in time and the other to…
-
3
votes2
answers347
viewsIgnore a specific Exception
In my try-catch, I want to record the exception that occurred within an object (for historical effect, necessary for the business rule, since this section takes place in a processing via integration…
-
3
votes1
answer342
viewsHow to make the keydown function work with the program in the background?
Code: if (e.KeyCode == Keys.F7) { A1 = !A1; } How to make this code work without the program being in the foreground?
-
3
votes1
answer1959
views -
3
votes2
answers757
viewsCreate a Stream object from a string
I need to create an object of the type System.IO.Stream from the content of a string. This one of mine string is in an archive Resource.resx. I get her back that way: string xml =…
-
3
votes1
answer125
viewsMemberwiseclone of aggregates
I have in memory (not yet stored in database) an object of type List<NotaFiscal>. I need to pass an item from this list as a parameter to a screen to make changes to that object. However it…
-
3
votes3
answers5094
viewsHow to download a file from a URL using C#
Developing a C# project I came across the following situation, I need to download files from some URL’s, what is the best way to do this? Would have some way to together the download implement a…
-
3
votes1
answer71
viewsCondition optimization
A comparison is possible (if 1 or equal to null) simpler than the one made in my code? @((Model.Visibilidade == 1 || Model.Visibilidade == null) ? "checked" : "")…
-
3
votes1
answer121
viewsIterate an array (vector) via Ienumerator? For what reason?
In which case it would make sense for me to give up iterating a array using loops "normal" (for/foreach/while) via index to use the IEnumerator as shown in Example 3? Example1 //Usando for int[]…
-
3
votes1
answer722
viewsHow to add a link column in Gridview?
I have the following code that generates my Gridview: protected void Page_Load(object sender, EventArgs e) { try { AlteracoesContrato alteracoes = new AlteracoesContrato(movimentacaoId);…
-
3
votes1
answer256
viewsInsert the value of an attribute into a textbox
I need to enter the value of the attribute SALDO class Conta in a TextBox. In java resgato via method get and convert with parse.float and Seto as string in the field. In C# as executed?…
-
3
votes2
answers154
viewsFind out if particular control is a button
I have the following code that serves to change the color of the buttons that are in a panel: private void mudaCorBotao(Button bt) { foreach(Control b in Panel_esq.Controls) { if (/*[O que devo…
-
3
votes1
answer66
viewsHow to find out in which generation of Garbage Telescope an object is allocated?
Considering my previous question on the generations of the CG, would like to understand if considering the "moment" through which an object is passing within its life cycle, brings some benefit or…
-
3
votes3
answers847
viewsHow to create Login and User in SQL Server passing command line through Visual Studio passing parameters?
public void CriaUsuarioSystem(string userSystem, string pwSystem) { try { conexao = new SqlConnection(conexao_BD); SqlCommand creatUserSystem = new SqlCommand("CREATE LOGIN @login WITH PASSWORD =…
-
3
votes1
answer371
viewsLambda - how to use the operator || (OR) in a . Any()
What would be the correct way to implement the line below, in Lambda? ListaDeRespostasPossiveis.Any(x => x.Nome == "respostaUm" || x.Nome == "respostaDois") I saw some examples in Stack Overflow…
-
3
votes2
answers211
viewsWhat value is verified in a condition operation with value assignment to a variable?
I have a method that does a check and return of this method stored in a type variable bool. When I perform this operation C# tests the value of the variable or the return value of the method?…
-
3
votes3
answers1491
viewsHow to replace the number of letters of a word with a character?
I’m doing a hangman’s game, let’s suppose I type the name "john" into a box of text, then I press a button and I want the "text 2" box to have "_ _ _", so I want the same number of underscore that…
-
3
votes1
answer191
viewsYoutube V3 API - Search videos by title
Hello. I’m using the Youtube V3 API to search for videos in a .net. project.I happen to have the exact title and need to search for it. In the documentation it is not clear if it is possible to…
-
3
votes2
answers114
viewsMethods with more than one Generic
It is possible to create a method using more than one type of Generic, sort of like this. public static TResult ToEntityForType<TResult>(this DataRow row, TType type) where TType : Type {…
-
3
votes1
answer3224
viewsInput string was not in a correct format
When calling the method below comes the message the input character string was not in a correct format private void SubmitData() { try { string user = usuario.Text; string pass = senha.Text;…
-
3
votes0
answers57
viewsError when using dictionary in a Iqueryable.Select() method to project columns chosen at runtime
The code fragment below aims to use the Select() method to perform generic column projections in a query, according to a list of column names provided. The program works fine if all columns are…
-
3
votes2
answers904
viewsHow to access properties of an object that is inside another object?
Deep down I want this output Console.WriteLine(cidade1.casas.dono); returns João using System; namespace arrayteste { public class cidade { public string nome { get; set; } public object casas {…
-
3
votes0
answers39
viewsWhat are structures for. NET?
What are structures for (struct) no . NET? What differs a class from a structure? In which cases would it be more feasible to use a structure than a class?
-
3
votes3
answers318
viewsDifference between properties syntax in C#
For what I researched, if I do: public int numero { get; set; } is the same thing as: private int numero; public int Numero { get{ return numero; } set{ numero = value; } } But in the first chunk of…
-
3
votes1
answer99
viewsHow to create an asynchronous method that is cancellable?
How to create an asynchronous method that is cancellable? In this context, the DoFoo() does things that cannot simply be stopped, like reading and writing files, and when canceling, I have to wait…
-
3
votes2
answers280
viewsLoop is not repeating as it should
I am creating a code that reads the number typed by the user and, if it is from 1 to 10, it performs the tabulation, presenting value to value on the screen, besides allowing the user to choose…
-
3
votes1
answer143
viewsCan I create a Win32 app in C#?
I am aware that C# is . NET Framework’s right-hand man, and that the default language for programming Win32 applications is C++. But, I can program an application in C#, independent of any . NET…
-
3
votes1
answer9941
viewsReturning difference between days and months
I am developing a C# function that calculates the interest applied to a given account. for this it is necessary to know the correct difference between days and months. How is it possible to execute…
-
3
votes1
answer270
viewsLock reading, opening and editing file
How to block the opening, reading and editing of a file by the user during the period the application is running? An application has a relatively long data collection period. This application reads…
-
3
votes1
answer1156
viewsUnable to create an instance of Activex control because the current thread is not in an STA
I’m trying to access a website through Webbrowser and this morning, suddenly, the following error appeared Unable to create an Activex control instance '8856f961-340a-11d0-a96b-00c04fd705a2' because…
-
3
votes2
answers289
viewsWhy doesn’t Return work?
I have a problem with return not work at all. For now I’m just printing on the console, so I’m replacing the return for Console.WriteLine(), but didn’t want to always have to do it. Here is an…
-
3
votes1
answer192
viewsIs it bad practice to do a lot of things inside a builder? Why?
Is carrying out heavy processing, such as queries to a database or consuming an API, within class constructors considered a bad practice? Why? public class Classe { private String dados; public…
-
3
votes2
answers161
viewsUse Contains in an integer C# field with lambda or LINQ
I have the following expression: query = query.Where(x => x.MeuCampoInteiro.ToString().Contains(filter)); But an exception is occurring: System.NotSupportedException: 'The expression…
-
3
votes1
answer115
viewsCodetemplate in . net core [scaffolding]
As in . net core 2.0 I do to create custom scaffolding templates? On the old system . net 4.6 copied the Codetemplates folder to the project. No . net core < 2 instavala o…
-
3
votes2
answers59
viewsHow to change the way a class/structure is printed?
I have the following structure: struct cores { int r, g, b; public cores(int r, int g, int b) { this.r = r; this.g = g; this.b = b; } } If I had a new structure printed, it would look like this:…
-
3
votes1
answer253
viewsHow to calculate days, ignoring the hours?
How can I calculate if spent 1 day ignoring the hours. Explaining, it would be more or less like this: I have a date 2017-09-09 11:45:20, normally it would have been a day when the 11:45 the other…
-
3
votes2
answers122
viewsIs it correct in MVC to access data within the model?
In a C# MVC project, it is correct to access data within the model? For example: public class Cliente { public int Id { get; set; } public string Nome { get; set; } //outros atributos... public void…
-
3
votes1
answer274
viewsUse of async with . NET Core and nhibernate
No. NET Core I know we have the async and await for request async. So far so good, but many frameworks in the market are creating methods with the signature MetodoAsync() and has the method without…
-
3
votes3
answers608
viewsLists repeating last added item
was studying about the lists in C# and I couldn’t understand what was wrong with my code (probably going to be very basic), all the items are the same as the last item added. I simplified the code…
-
3
votes2
answers92
viewsHow to make a function that takes two integer vectors and returns a boolean value?
I want to make a function that takes two integer vectors and returns a value Boolean, but when I put the: return (encontrou); It keeps error on the variable encontrou. Follows part of my function:…
-
3
votes1
answer148
viewsConvert Dynamic to query string
Is there any more "elegant" way to convert a dynamic for a query string? I’m currently doing with several Replace() but it’s not quite what I wanted. string data = new { email = email, password =…
-
3
votes1
answer509
viewsTake values separated by spaces in C#?
I want to take the values, for example, 79 201 304 and store in one vector each number at one position. Example : int array[0] = 79; int array[1] = 201; int array[2] = 304; public static int…
-
3
votes2
answers1207
viewsLeft Join with three or more lambda tables
I have the following consultation on SQL: select e.idEstado, e.txtNomeEstado, e.txtSiglaEstado, c.idCidade, c.txtNomeCidade, de.txtH1, de.txtTitulo, de.txtDescricaoEstado, de.txtDescription from…
-
3
votes1
answer142
viewsPerformance Itextsharp
I’m doing the reports using iTextsharp and the result has been acceptable, but working with many records has become slow. Currently I do so: I capture the database data (storing in a DataTable); In…
-
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
votes2
answers2574
viewsLINQ using function inside select new{} with lambda Expression
I am assembling a select, with the Entity Framework, which needs to "create a column" according to 4 criteria. I am trying this way: IQueryable<ImoveisDTO> Resultado = ctx.Imoveis.Select(ib…
-
3
votes2
answers655
viewsMysql parameter error with C#
string sql = @"UPDATE ivendas SET nritem=(@rank:=(@rank+1)) where id_venda = 20"; try { MySQLBase basemysql = new MySQLBase(); MySqlCommand cmd = basemysql.connection.CreateCommand();…