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
answers1349
viewsHow to convert a nullable int to common int
I have a method that gets an integer that can be null, if it happens some executions of methods, but when I will use the same variable in a place that uses int which cannot be null, it appears that…
-
4
votes1
answer1002
viewsUpdate Many to Many Entity Framework c#
I am having difficulty updating a record with entityframework, I will inform the whole structure below. In short, I have a register of artists, where these artists are related to categories.…
-
4
votes2
answers588
viewsHow to open the Mainpage.axml of a Xamarin Project in Designer mode?
So, I recently downloaded Visual Studio 2017 and came across the Cross-platform Application (Xamarim.Forms or Native), when I create it 4 projects are generated. The App1; App1.Droid; App1.IOS;…
-
4
votes1
answer58
viewsDifference in EF exclusion forms
I want to know, what is the difference (if any) in the form of exclusion using the RU db.Contexto.Remove(objeto); db.SaveChanges(); And using the EntityState.Deleted; Db.Entry(objeto).State =…
-
4
votes1
answer3602
viewsLinq Compare two lists of different types
I have two different lists A List<ProdutoTag> and B = List<Tag>: public class ProdutoTag { public Int64 ProdutoId { get; set; } public Int32 TagId { get; set; } public Double Peso { get;…
-
4
votes1
answer2601
viewsWhat is the difference between Show(), Showdialog() and Application.Run()?
I read something about modal but did not understand, someone could explain?
-
4
votes1
answer308
viewsHow to cast exception in SQL and treat in C#
I’m creating procedures in an SQL Server database. To clear a brand, I first check if the brand is already tied to a product before deleting. CREATE PROCEDURE SP_Delete_MarcasProdutos @Id int AS…
-
4
votes1
answer1975
viewsCalling an asynchronous function in an Actionresult?
How to make the call of an asynchronous function on a non-asynchronous controller, to be clearer follows a situation: I have a form that when saving it needs to store data in the database and…
-
4
votes1
answer104
viewsSearch does not recognize file . zip as valid archive inside a folder
I did this routine to delete empty folders, no files inside. foreach(var folder in folder_new) { if (Directory.Exists(folder)) { if (Directory.GetFiles(folder, "*",…
-
4
votes3
answers351
viewsGroup by days interval using Linq
How can I use interval grouping with Linq? var dados = new[] { new { Id = 0, dias=100, preco= 25, Nome="etc"}, new { Id = 1, dias=40, preco= 50, Nome="etc1"}, new { Id = 2, dias=50, preco= 55,…
-
4
votes1
answer665
viewsHow to pass a txt file to a Stream type parameter?
How to pass a file txt for a Stream type parameter? That’s the ActionResult which calls the method to read the file txt: [HttpPost] public ActionResult Incluir(ContaReceberViewModel pContaReceber,…
-
4
votes2
answers287
viewsHow to add methods to a native class?
How to add functions in a native C#class, in my case I tried to do in System.Math only as a test: public class Math { public static double test(double a) { return a; } } And call it that:…
-
4
votes1
answer681
viewsHow to check if a file is an image?
I am working on an application using ASP.NET MVC and Angularjs and need to ensure that the file upload will only be image files, even if someone sends an extension of another type of ". jpg" for…
-
4
votes2
answers836
viewsWhat code should be used to focus a Textbox?
What code should be used to focus a Textbox? I am creating a system, where I need that when the client keystrokes ESC, the focus of the textbox is lost. How do I do?
-
4
votes1
answer386
viewsRecover Volume Name of Netmapped Disk Drive
I’m using DriveInfo.GetDrivers() to take the names of the disk drives present on the machine and list them on a TreeView. I made the code below that works, however it does not appear the names of…
-
4
votes1
answer555
viewsBootstrap Nav-tab event to run on the c#server side
I am using the following code to use tabs in my Asp.Net application, is there any way to add an event so that when switching tab run some event on the server side equal to the ajaxcontroltoolkit…
-
4
votes1
answer562
viewsView SQL at Runtime
Is there a monitor that shows me the sql script at runtime? For example, during debug, I would like to see how the script was mounted by the following code: var q = (from proc in…
-
4
votes2
answers105
viewsinterpret string C#
hello, needed to resolve a string with an account (e.g. 2 + 2) in C# and return an integer (e.g. 4) static void Main(string[] args) { string str = "2 + 2"; int resultado = Calcular(str);…
c#asked 7 years, 2 months ago Jackson José Gomes Do Valle 85 -
4
votes1
answer1524
viewsWhat is the Expect100continue property for in System.Net.Servicepointmanager?
I am working on a system that manages customer licenses. There is a feature in my system to return the customer’s product key , making a query on Web Service. And simple you inform the CNPJ it…
-
4
votes1
answer662
viewsNo Auto-Increment Primary Key for CPF in Entity Framework
The scenario is as follows: I have an Employee class. A primary key of it must be the employee CPF that the user type. The Problem: the key follows a default auto increment, not going according to…
-
4
votes3
answers4235
viewsDifference between Console.Write() and Console.Writeline()?
What’s the difference between Console.Write() and Console.WriteLine()?
c#asked 7 years, 2 months ago who who who who 653 -
4
votes0
answers853
viewsPost Office - PLP XML
In the Postal web service there is a process of sending plp (pre-mailing list), which contains information of the postal objects. I’m sending this plp by the method fechaPlpVariosServicos. But when…
-
4
votes2
answers324
viewsWhat is the correct way to use Runonuithread() in Xamarin.Android?
When I need to update a field on the UI, I need to run this code on the UI thread? For example: I have to change my layout Activity. The code I’m using is this: RunOnUiThread(() => {…
-
4
votes1
answer389
viewsDodging an Obstacle without Navmeshagent
I need to create an obstacle clearance script but I can’t use Navmeshagent because this project depends on implementations where the Navmeshagent doesn’t work. See that in the image below there are…
-
4
votes2
answers161
viewsProtecting data in memory
I read several articles on cryptography etc... The cryptography reported by posts was a success in my program, however some data remains in memory being vulnerable to Assembly readers in real time.…
-
4
votes1
answer101
viewsCS1526 & CS8032 error
By error translation says I have to put a ")" at the end of "type" however now there is a ")" at the end of the "type" I tried to change to "[ ]" but it didn’t work I tried to put 2 ")" as I have…
-
4
votes2
answers2098
viewsDisplay decimals (Currency) is rounding
I have an application where the price should go in format int decimal-free. int Valor = (int)(produto.Valor * 100); //o produto.Valor é um decimal The problem is when I want to display this value in…
-
4
votes1
answer1339
viewsHow to get attribute of a generic type object?
I’m having difficulties p/ retrieve an object to get a specific attribute. I want to overwrite the method Equals in my class, to compare whether the title of objects are identical. In this case, it…
-
4
votes1
answer344
viewsDifferences in constructors using property vs field (field)
namespace WMB.CieloB { internal class FuncoesCielo { internal FuncoesCielo(int iDC, Boleto boleto) { IDCliente = iDC; this.boleto = boleto; } public int IDCliente { get; set; } internal Transaction…
-
4
votes2
answers254
viewsCRUD with images , working with Httppostedfilebase and byte[]
We are using Entityframework with Codefirst and Database Postgresql. There are some tables that should save images, and the POCO classes are referenced as byte array. Up to that point all quiet. I…
-
4
votes2
answers1359
viewsSearch specific value within a file . txt C#
I have a. txt file with the following lines: 000-000 = CRT 001-000 = 00000021 009-000 = 00 012-000 = 247823 013-000 = 0000559877 022-000 = 24082017 023-000 = 152842 032-000 = 80F1 100-000 = JORGE…
-
4
votes0
answers285
viewsService returns me cast error when consumed
I decided to make another post, since the subject is another, although in the original post, in the comments we touched on the subject, but no depth. I have that mistake:…
-
4
votes1
answer2526
viewsRecover view value for controller
Goal: Retrieve view value for controller [Httppost] I created a Generic class with gets and sets public int ListarDadosCarteira_Resultado { get; set; } public string ListarDadosCarteira_Descricao {…
-
4
votes1
answer1398
viewsWhen to use String and Stringbuilder
There is another question about What is the most appropriate way to concatenate strings?. It explains the possible types of concatenations in C#. But when should we use System.String and when we…
-
4
votes1
answer1210
viewsHow to decrease byte array size that represents an image
I have an array of bytes in Base64 that is in a string in C#. It represents an image. The size of the string is between 50 and 80 thousand characters. I wanted to know if it has how to decrease this…
-
4
votes2
answers2566
viewsLogin with Windows Authentication on IIS
I have a base Sqlserver 2008 where all users can connect to it via Windows domain, this works properly via SQL Management Studio. I am making a C# Application in MVC, and I wanted that when the user…
-
4
votes2
answers1079
viewsEvent loading when conducting queries in AJAX with ASP.NET MVC
I’d like to know how to best place a Waiting to identify that the data of a survey is being processed, in case I have a table and can perform a search filter, when the request is sent I would like…
-
4
votes3
answers113
viewsHow to implement custom features in a model on . NET?
I needed to implement some features in the model users but as you can see early on this class is automatically generated by Entity, so whenever I upgrade or recreate the model the custom…
-
4
votes2
answers3351
viewsHow do I create a Checkbox using the Html.Checkboxfor Helper for a Nullable field?
My field is as follows in my class: public bool? meuCampo { get; set; } And in my view it’s like this: @Html.CheckBoxFor(m => m.meuCampo) Only that way it’s not allowed, because I can’t…
-
4
votes2
answers569
viewsReturn Datareader to bool field
I need to return a field that is of the type bool: public List<TB_USUARIO> ListarTodos() { var strQuery = "select * from tb_usuario"; using (contexto = new Contexto()) { var retornoDataReader…
-
4
votes2
answers233
viewsWhen I type broken number, it removes the comma and sums as integer
static void Main(string[] args) { Console.Write("Digite sua primeira nota: "); double n1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Digite sua segunda nota: "); …
-
4
votes2
answers315
viewsWrite Fileupload Path inside an ASP.NET Updatepanel
Expensive, The question of my doubt is very simple. How do I save the path of my Fileupload file to some control or Viewstate, with this Fileupload being inside an Updatepanel? I’m actually using…
-
4
votes1
answer421
viewsSend an SMS to one of the contacts
I have an app and at the end I wanted to send a msg to one of the user contacts about my application. var columnNumber = cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Phone.Number);…
-
4
votes2
answers1328
viewsIs it safe to use List with Parallel.Foreach?
I’m making one by making a style method Crawler which receives a string list, makes a call on a website, inserts the return into another list and returns. My method is working, but it’s too slow, so…
-
4
votes1
answer115
viewsWhat is the best way to make multiple requests to an API?
I came to ask this question once again thinking that it would be beneficial for the community to have a canonical way of making several http requests to a particular API. More specifically this…
-
4
votes3
answers68
viewsUnity5 engine error in code
I was creating a code for the one game and in the end appeared some problems: Assets/Scripts/Player/PlayerMovement.cs(63,23): error CS1547: Keyword `void' cannot be used in this context…
-
4
votes1
answer58
viewsError using Split inside Select
Why the exception below occurs when using Split within a Select in a IQueryable? The LINQ Expression Node type 'Arrayindex' is not supported in LINQ to Entities. I already managed to solve the…
-
4
votes3
answers342
viewsHow and where to implement business rules in the Entity Framework?
I have the following example of a software that uses Entity Framework, accessing a database with only one table called Produtos with the following fields: Field int produtoid. Field string…
-
4
votes1
answer730
viewsConsuming Java Web Service
I’m a beginner in C#, my Visual Studio is 2010, my version of Windows Phone is 7. I searched the internet and this version of the "async" command only works from Visual Studio 12 to top. Is there…
-
4
votes1
answer420
viewsMulti Thread Socket Server and its Clients talking to each other
I have a question that is killing me and I would like to share with you, maybe someone has the answer or a way forward to address this doubt. I have good experience with Web/Desktop development,…