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
votes3
answers707
viewsSum table values
I have a table where I return the amounts paid per taxpayer monthly. But I need to create a subtotal field, adding up the values of each month. Very similar to the Fibonacci sequence. The problem is…
-
3
votes2
answers2092
viewsFill all fields of an Object iteratively
I have a Class public class Objeto { public int _numero { get; set; } public DateTime _data { get; set; } public string _palavra { get; set; } public decimal _decimal { get; set; } } Is it possible…
-
3
votes1
answer49
viewsPrealoder when requesting dowload
I’m making a return of a pdf from a Custom ActionResult response.ContentType = "application/pdf"; response.AddHeader("Content-Disposition", "attachment; filename=teste.pdf"); And I wonder how I…
-
3
votes2
answers700
viewsHow to add a`ul` to a`li` HTML element via c#code?
I’m going to have a list of multiple clients, and I wanted to add these clients to one ul of the element li in HTML, you can add these clients dynamically (because each search performed on the…
-
3
votes2
answers4494
viewsScroll through a list of characters
I have a method that checks the number of characters in a string, and separates them into variables with the information as can be seen in this example. The problem is when you have a list of data…
-
3
votes2
answers208
viewsI need a code that gives the error Accessviolationexception
My teacher passed a series of exercises and in them I need to create a code to give the error AccessViolationException. However I am not able to create a code that of this error (I am not willing to…
-
3
votes1
answer145
viewsConvert.Changetype converts data incorrectly
The method Convert.ChangeType is converting the date the wrong way I hope 24/02/2015 and comes 23/02/2015. Does anyone know why? Code example: using System; using System.Globalization; namespace…
-
3
votes1
answer226
viewsHow to force an Exception when trying to delete a Master record that already contains relationship in a Child Record?
I created the following structure in SQL Server: Using Entityframework with Code-First the classes stayed that way: [Table("Master")] public class Master { [Key]…
c# sql-server entity-framework entity-framework-6 relationshipasked 9 years, 6 months ago Severo 299 -
3
votes1
answer2202
viewsHow to implement token to reset password?
I have an Asp.Net MVC project that I created without template (from scratch even). I would like to implement a password recovery function, but I’m not sure where to start. What method is used to…
-
3
votes3
answers339
viewsConnection to the bank is open in static method?
I have the following static class available for the entire application: public static class MinhaClasse { public static void Salvar(Item meuItem) { using (MeuEntities db = new MeuEntities()) {…
-
3
votes2
answers84
viewsReturn the path value
To return the value with the name of a folder in C#? Example, if executed: Directory.GetFiles("%PROGRAMFILES% (x86)\MyApp", "*.*", true); And if he succeeds he returns like this: %PROGRAMFILES%…
-
3
votes1
answer51
viewsDisplay a Direct Message on the Mainpage page
How to display a direct message from Mainpage, I am using Messagedialog as code below: namespace App4 { /// <summary> /// An empty page that can be used on its own or navigated to within a…
-
3
votes2
answers1052
viewsPass data encrypted by URL in ASP.NET MVC
I need to pass a link, but I didn’t want to leave it too exposed, I would like to know how to encrypt at least the object id. I created a class for Cryptography, only it generates "/" and this puts…
-
3
votes1
answer380
viewsHow to insert values into a relational table when inserting a Row and get this ID?
I am building a program to insert data from excel files into a database. My database has this structure: Tables (and fields): Schedule (Id (PK), Starttime, Endtime, Dayweek, Roomid (FK), Classid…
-
3
votes1
answer332
viewsHow to format values with custom string formats?
I am developing a graphic and would like to put the values of the Y axis as the image below: I have verified that it is possible to do this through custom string formats in that way…
-
3
votes2
answers94
viewsSimplify LINQ p => p.Tipo.Toupper(). Equals("S") && p.Modo.Toupper(). Equals("S")...,n
How to simplify LINQ expression? p => p.Tipo.ToUpper().Equals("S") && p.Modo.ToUpper().Equals("S")...,n
-
3
votes1
answer187
viewsLinq query with Count
I’m doing a query that has some joins and a Count, but I want to do it with Linq. This is my Query. sbSQL.Append("SELECT grproj.cdgruproj as Id, grproj.dsgruproj as DescricaoGrupoProjeto, ");…
-
3
votes2
answers399
viewsDoubt about HTTP POST
I’m trying to text through a Webservice. To send a single SMS is simple. Just use the URL in this format:…
-
3
votes1
answer177
viewsCan you use Firebird by accessing from your Windows Phone?
I developed a C# Windows Forms application with Visual Studio 2013 and Firebird database, but I would like to make a small application to facilitate access to the system. However in this application…
c# .net visual-studio-2013 windows-phone firebirdasked 8 years, 12 months ago André Morais Martins 367 -
3
votes1
answer326
viewsWhat is the difference between Ienumerable<T> and Ienumerable?
I tried to see the code of both interfaces, but the only difference I see is the IEnumerable<T> has the method IEnumerator<T> GetEnumerator();, and that at the interface…
-
3
votes1
answer121
viewsGoogle Returning 403 Forbidden
My webservice makes a request to maps.google.com but returns Exception happens System.Net.Webexception with 403 Forbidden message But the URL normally runs via browser. What can be? [WebMethod]…
-
3
votes3
answers8198
views -
3
votes1
answer72
viewsGetting all values on Lambda
My code has the following structure: var a = ViewData["a"]; var b = ViewData["b"]; var c = ViewData["c"]; var d = ViewData["d"]: foreach(var x in ObjetoE).where(x=> x.A == a && x.B == b…
-
3
votes1
answer791
viewsproblem with update Entity Framework 6
This is my method of updating: public dynamic Atualizar(TEntity obj) { dynamic data = null; using (ClassContexto ctx = new ClassContexto(ClassMaster.conexao())) { try { ctx.Entry(obj).State =…
-
3
votes1
answer718
viewsHow to convert an Array of Bytes to a Direct Image in Listview?
I populated THE Datasource of Listview with a collection. The collection contains a field with ArrayBytes. I need to convert to the image appear in control. But the conversion has to be direct in…
-
3
votes1
answer139
viewsConcatenate project name to create Template in Visual Studio 2013 c#
I am creating a template for project creation and when editing the file . vstemplate I have something like this : <VSTemplate Version="3.0.0"…
-
3
votes1
answer320
viewsCreate item in another project Visual studio 2013 Template
I am creating a template in visual studio, but I want to add an item in a project to be created in all other projects of Solution, can anyone help me? the code is more or less this: <VSTemplate…
-
3
votes1
answer695
viewsHow to pass text from textbox to report, with VS 2015, in C#?
I’m creating an app for where I work, which should print some information-based labels that I enter into a form I created. For that, I’m creating a smaller version, to test if everything I want…
-
3
votes1
answer562
viewsC# Mysql transaction in distinct classes and methods
How do I interact a transaction between 2 methods that are in different classes? In my method where I open the transaction is as follows: public string InserirFuncionarioM(FuncionariosDTO…
-
3
votes2
answers1257
viewsError when configuring application in IIS Local (Integrated pool)
Personal hail, I am new with . net and am in error when creating an application in iis local. Below print of the exception and my pool. My iis resources and project are the same as a friend’s and on…
-
3
votes1
answer245
viewsHow to map a read-only property in Fluent nhibernate, error when identifying Setter
I have a property that must be read-only, I performed mapping via code and assigned the parameter to read-only, however, it presents me an exception stating that the property’s Setter was not…
-
3
votes3
answers133
viewsWhere are the elements selected by LINQ stored?
I’m studying LINQ now and hit me a question: A LINQ that runs without the methods ToList() or ToArray() returns a IEnumerable<>, right? But a IEnumerable<> is not exactly a list/array,…
-
3
votes1
answer449
viewsAdd line to Datagrid with Datasource defined
I have a DataGridView who has the DataSource setate with List<MinhaClasse> and would like to add a new line to it. I know this is not possible using the method AddRow() of DataGrid. Is there…
-
3
votes3
answers1947
viewsDropdownlist validation in ASP.Net MVC
I’m having trouble validating my dropdown in a view. In my template I use an Annotation Required as shown in the code below: Model [Required(ErrorMessage="Informe uma cidade")]…
-
3
votes1
answer271
viewsWeb service security attributes
You can use the AuthorizeAttribute in asmx, Soap or Rest? webservice and custom attributes, such as the below (example only)? [System.AttributeUsage(System.AttributeTargets.Class |…
-
3
votes1
answer514
viewsEntity Methods in DDD architecture
Could you help me with a question. In DDD architecture what types of methods should I put in my Entity and which ones should I put in my Domain Service? I know that in my entity I must put at least…
-
3
votes1
answer505
viewsI am unable to extract a zip file to a folder
The code is giving this error: A first chance Exception of type 'Ionic.zip.Zipexception' occurred in Ionic.zip.dll Additional information: Cannot read that as a Zipfile If there is a Handler for…
-
3
votes1
answer1235
viewsDestruction of an instance
How do I destroy an instance? I have an object whose instance is referenced in various parts of my code. At some point I need to delete this object and for that I am doing the following: meuObjeto =…
-
3
votes1
answer1136
viewsFor Rotation on Z-Axis
I’m new to the c# code and I’m doing a basic Z-axis rotation in Unity 3d, but I’m having a problem to stop rotating. The initial code is this: using UnityEngine; using Sysstem.Collections; public…
-
3
votes2
answers725
viewsHow can I save TXT file in C: directory using C#?
I’m trying to make a small data scrolling program and I want it to save a file. txt that stores the scrolls, so that it can be read later. The program is practically whole ready, all functionalities…
-
3
votes2
answers858
viewsKeydown + Enter event. Clear keyboard buffer
I created an example Winform C# . net containing textbox1, textbox2 and button1 to simulate the following situation: When starting the application, the textbox1 gets the focus and when we press…
-
3
votes1
answer256
viewsDoubts about implementation of Lazy Load and Dependency Injection
The scenario is simple, it has a Personal Physical class that has linked to it a list of Contacts (instances of physical persons), Telephones (instances of an entity Telephone) and a list of…
c# asp.net pattern-design dependency-injection lazy-loadingasked 9 years, 5 months ago Intruso 1,625 -
3
votes2
answers928
viewsHow to scan a string and check content within it?
I need to do a check with a certain text within a string. How do I go through this string and search the text to make this check ? Example: If(dentro da string contém "Olá") { Mostre o valor…
-
3
votes1
answer1326
viewsHow to locate an image without informing the absolute path?
How to locate an image without entering the absolute path? Image img = System.Drawing.Image.FromFile("~/Content/images/SemFoto.jpg"); I tried several ways and could not capture the image without…
-
3
votes1
answer1677
viewsError 242 while consuming Nfedownloadnf
I’m trying to consume the NFE download service on the farm: https://www.sefazvirtual.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx but I have obtained the following error: ERROR: 242 Reason:…
-
3
votes2
answers372
viewsCollate Mongodb
I need to make an auto complete that consumes a Mongodb database. The words can be written with or without accent, uppercase or lowercase, that is, I need to define a collate in the Ngo that allows…
-
3
votes1
answer1209
viewsHow do I use @Html.Actionlink to create links to a multi-trace route?
I’d like to use @Html.Actionlink to create the following link: http://localhost:59278/video/categoria/new-movies/3 Being that my control is: [Route("video/categoria/new-movies/{page?}")] public…
-
3
votes1
answer513
viewsWhat’s the best way to get information to View?
I have the following code: public ActionResult AtualizaCliente(int id) { ViewBag.idFoto = new SelectList(dao.fotos, "idFoto", "Foto"); ViewBag.idInformacao = new SelectList(dao.informacoes,…
-
3
votes1
answer97
viewsUse viewbags for metadata or place them in a Viewmodel
In the scenario below, I own a View that depends on some ViewBags to fill in options in selects html. When performing the POST and if something goes wrong in the registration, the user is redirected…
-
3
votes1
answer440
viewsTake the file path opened by the process name in C#
I have an application that works based on the client’s current process. I need to get the name of the file and its absolute path when opened. That is to say: If for example the client opens the…