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
votes1
answer95
viewsHow to popular a parameter property with GET access
To understand what I want to do, note the Formclosing() parameter of Windowsforms: private void Form1_FormClosing(object sender, FormClosingEventArgs e) { var r = e.CloseReason; } By analyzing this…
-
4
votes2
answers79
viewsHow to create hierarchy functions? Ex Console>Error>Writeline()
My question may seem confusing so I’ll explain. Imagine that I have three class: Program, Controle.cs, Volume.cs. class Program using System; namespace ConsoleAppPOO { class Program { static void…
-
4
votes2
answers123
viewsHow does a method with the same name return more than one object type?
I am implementing the Google Drive API and I came across the following situation: var fileMetadata = new GoogleDriveAPIV3.Data.File() { Name = "folderTest/testeUpload.jpg" };…
-
4
votes2
answers146
viewsFormat decimal places in Forms
I need to format the decimals and I can’t. What is the correct way to do the formatting in this case? double peso, altura, imc; string nome; nome = txtnome.Text; peso =…
-
4
votes2
answers609
viewsDifference between ?. and ?? in C#
I looked at the documentation of Microsoft but still I found it a bit confusing, the main things I managed to abstract were: "?." - is a conditional null operator and tests the value of the left…
-
4
votes2
answers915
viewsSelecting an Item from a List<T> with index equal to the iteration value of for
How can I select an item from a list by the index, this being equal to the iteration value of a for? I tried to accomplish using LINQ, while compiling and inspecting the StringBuilder which would…
-
4
votes2
answers176
viewsDoing a LINQ function that can be called in an EF query
I have the following expression: Where(cd => cd.Modal == modal) .Select(s => s.Volume) .DefaultIfEmpty(0) .Sum() what use to make a same calculation several times within a few querys through…
-
4
votes1
answer98
viewsBug to popular a Data Gridview in Window Forms
To popular my grid the values are not aligned correctly, as the image below. This is my Load Form code: DatabaseRepository db = new DatabaseRepository(); var colunas = db.GetColumnsName(); var…
-
4
votes1
answer160
viewsError signing xml passing PIN automatically
I have this code that selects the certificate according to the serial passed: public static X509Certificate2Collection SelecionarCertificado(string serial) { X509Store store = new…
-
4
votes1
answer199
viewsHow to read an XML that is inside the project?
I’m creating a web application with .NET Core Razor and I need to get my code to read a file XML. I can already get him to read this XML, but with another path, which is out of my project. That is,…
-
4
votes1
answer85
viewsWhy use parameter modifiers?
While writing functions and subroutines, we use parameters to interact with the function algorithm. These parameters can have several purposes, such as passing a value, a reference, or leaving a…
-
4
votes3
answers290
viewsHow to make compatible objects coming from two different classes, derived from the same interface?
I have an interface (I’ll call it ICliente) which is used as a contract between an application and a DLL. public interface ICliente { int Id {get; set;} string Nome {get; set;} ... } This interface…
-
4
votes2
answers884
viewsProblem with currency percentage and rounding
How to maintain monetary values with only 2 decimal places when performing percentage operations? Example: Total value: R$ 377,17 Percentage divisions: 33%, 33% and 34% Problem: the sum of the value…
-
4
votes1
answer113
viewsHow should I assign strings in C#?
As far as I know, System.String no. NET (I don’t know if on other platforms the string type is also like this) is immutable, ie if I do: string a = "texto"; a = "outro texto"; Behind the scenes, by…
-
4
votes3
answers214
viewsError: "Return should not be followed by an object expression"
I have this function that has a simple registration but is not registering My doubt would be on that return RES; which gives the error message below the code. //botao para cadastrar OS private void…
-
4
votes1
answer142
viewsProblem with System.Indexoutofrangeexception in C#
I need to create a class Marca and a Modelo, both related to cars, where model will know your brand and brand should know your models. Model Class: namespace AssocMatrizes.Model { class Modelo {…
-
4
votes2
answers54
viewsMark Previous Check (Parent) to Node
What I need is that when selected Item "Ball" which is a child node of check "1031-HUBCAP ...", the Father node is selected as well. Or Do not let select the child node if the parent node is not…
-
4
votes1
answer54
viewsExpression generation for EF with dynamic properties
I’d like to conduct a search on where for Entity Framework passing the name of the property you would like to compare as a string. For example, I have the following classes: public class ClientData…
-
4
votes1
answer213
viewsStackoverflow error when compiling code in C#
I am doing an exercise in C# and I am not able to find the error in my code, because I have already checked the resolution of the problem and I can’t find the difference in the syntax of the code…
-
4
votes1
answer138
viewsTake two values from Arduino and display in C#
I have two Ultrasonics linked in my Alpha, and I’m using this code to read their values normally: #include <Ultrasonic.h> Ultrasonic ultrasonic(11, 12); Ultrasonic ultrasonic1(8,9); const int…
-
4
votes2
answers83
viewsForm closing without close()
Dear friends, I have a very simple form that is closing after clicking OK on Messagebox. I have already reviewed everything, compared it with other papers I have and I haven’t found the solution. If…
-
4
votes2
answers123
viewsHow far should we follow OCP?
When developing a screen for a certain part of a system, I come across a classic situation of owning some ifs to determine what action should be taken. I then linked this case to examples of OCP…
-
4
votes1
answer204
views"Close" DLL opened
I created a dll to run in Runtime a class: var classe = "using System; " + "public static class CSharp" + "{" + "public static double Executar()" + "{" + "return 0;" + "}" + "}"; var compilation =…
c#asked 4 years, 10 months ago LeoHenrique 954 -
4
votes3
answers137
viewsSQL Query - ORA-01795
I need to make a report from a database query. The problem is that the query returns more than 1000 expressions and presents the following error: ORA-01795: the maximum number of expressions in a…
-
4
votes1
answer115
viewsCreating a dictionary with void functions
I am for fun to develop a TCP server in C# that performs functions depending on the message that the connected client sends you, for now, I only managed to do what I want with functions that return…
-
3
votes2
answers578
viewsHow do I always keep my Urls in lower case?
I want all Urls on my site to be lowercase to help with SEO and to make link sharing consistent. How can I do that?
-
3
votes0
answers582
viewsIs there a tool that manages documentation similar to MSDN?
Is there a program that transforms the documentation of my code (I can generate .xml) into MSDN-style pages? Or a wiki format?
-
3
votes1
answer447
viewsHow can I write values in the memory of another process?
I have the memory address, the process and the value. // Processo var p = Process.GetProcessesByName("ePSXe").FirstOrDefault(); // Endereço IntPtr addr = new IntPtr(0x00A66E11); // Valor var val =…
-
3
votes2
answers3847
viewsIs it possible to assign the default value of a property with an attribute?
I wish I could declare a property as: [DefaultValue(10)] public int Maximo { get; set; } And when I was going to use it, it already came with the value started in 10. However the attribute does not…
-
3
votes1
answer304
viewsWhy does keybd_event not work in some contexts?
I want to understand why keybd_event doesn’t work in some contexts. For example, it does not work in games with League of Legends or emulated games on ePSXe. The following code: Keys key = Keys.Q;…
-
3
votes1
answer705
viewsHow do I make my Master Form know when a secondary form has been closed, without using Parent and Child?
I have my main form (image below), and in it a Split Container. I open a secondary form (which is currently displayed) on panel2 of SplitContainer, where the user selects an account to perform…
-
3
votes2
answers408
viewsWhat is the simplest way to recover certain elements of an XML with Linq?
I got the following XML: <clientes> <cliente> <documentos/> <livros> <livro nome="Nome1"/> <livro nome="Nome2"/> </livros> </cliente> <cliente>…
-
3
votes1
answer1363
viewsIs there a way in ASP.Net MVC, in the controller to access a variable in sessionstorage or localstorage?
I need to get the value of a variable stored in sessionstorage through a controller where this method is not passed the parameter of this variable. Session/localstorage are managed through…
-
3
votes4
answers7116
viewsHow to hide the time of a "Datetime?" field in the user interface?
The time is appearing for the user. My question: it is possible to hide the time and show only the date? How are you showing: Model code: View code:…
-
3
votes1
answer4824
viewsUndefined object reference for an object instance
I created a DLL with the option "Register COM Interop" in C# where some Webservices from different prefectures are consumed. I use this DLL in a Windows Form C# test application where no error…
-
3
votes1
answer1046
viewsWhat is the best way to make an online database backup
There is a client of mine who owns two machines, one of them is the server where all the data of the bank is, and the other is the cashier. However, there is customer concern in case something…
-
3
votes3
answers3055
viewsWeb service in javascript
How to consume a Web Service by javascript using Visual Studio? I did a search and found a way to perform with Jquery but never used this before. I need to consume this Web Service to search for…
-
3
votes6
answers6055
viewsPart of the Label in Bold?
How to place a part of the string of a Label in the Windows Form in bold via code in c#. Someone knows something via code for that?
-
3
votes3
answers14922
viewsConsume webservice dynamically
I am developing an Asp.net+c# application that will access some public webservices. I would like to do something flexible and easy to maintain in the future. I thought of calling the webservice by…
-
3
votes5
answers1583
viewsHow to get the number of weeks in a date range in C#?
I would like to know how to know the number of weeks in a given date range in C#.
-
3
votes1
answer5980
viewsHow to pass parameter in an Action Link values that are in HTML elements?
I have 2 HTML elements, a TextBox and a Hidden, which have values, how to pass the values of these elements in the Action link parameter? Below the parameters docItemId and vlrImobIcms are making a…
-
3
votes3
answers166
viewsForm waiting for a request
Problem My form makes a statement requisição a database (select, insert, update, delete values), but whenever these requests are made a lock occurs in the form (a freeze)! How to prevent forms from…
-
3
votes4
answers3223
viewsGenerate xml through a class, even without value in the property
I am generating an xml through an existing class, for example [XmlRoot("pessoa")] public class pessoa { //[CPFValidation] [XmlElement("cpf")] public virtual string cpf { get; set; }…
-
3
votes2
answers1169
viewsSave form data in session
I created an access form for my administrative area, using a tutorial by Microsoft. Now I need to retrieve the login that he typed to enter and show it on an administration page, and also to make…
-
3
votes1
answer79
viewsHow to add "Buttons" to Tabbedpanel
I am involved in a personal project in which I intend to elaborate a calculator with some items that are inserted in "arrays". I opted for a class called "Calc.Cs" to build a method with a code…
-
3
votes1
answer737
viewsLoop asynchronous calls and process data at the end of all runs
I have a method of web service which receives the IP of a server as a parameter and returns a DataSet. Several servers must be consulted by this web service, Um List<string> contains the list…
-
3
votes2
answers2181
viewsPass Javascript data to C#method
I need to get a user’s location, go to C, get his street data and show it on a label. I have the following code: Labels <asp:Label ID="lblMsg" runat="server" Visible="true"></asp:Label>…
-
3
votes2
answers428
viewsHow to remove the option selected in multiple Comboboxes?
I have several components of the type ComboBox with identical options. The user must select one of them(e.g. "Name"). How to do so when an option is selected, in any one ComboBox, she disappears…
-
3
votes1
answer149
viewsHow to exchange the text of a cell of a table that is inside a Flowdocument that is in a Richtextbox
I am trying the following code to replace the text in the question situation, where rtb is the richtextbox, .Document is the flowdocument. The text is exchanged in Run (r), but when I open the…
-
3
votes2
answers538
viewsHow to update ASP.NET Repeater in real time?
I have a Repeater in a lateral div that receives the quantity of products from the cart and needs to be updated every click. I’ve tried to rpt.Databind() in the Click event but the Reset only…