C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

Share tech news, updates, or what's on your mind.

Sign up to Post

I have c# aspx.net with ms SQL server and have one question about SQL

assume I have a web form and come with start date and end date. the format is 20181201 and 20181231 and they are an integer.
and I have to run a SQL statement like below.

select top 1 * from transacation_history where deposit_date >= 20181201 and deposit <= 20181231
Or
I should use between statement? but I do not know how to do that.
1. Which one run faster?
2. I will convert it into stored procedure. In this logic, is it best practice in ms sql?

Thanks.
0
What is the difference between a class, struct, and static class?

How would you decide to use a interface?
0
I have a web server in an AWS VPC.  
Only about 50 IP Addresses are open to see the page on this server.  I filter the IP addresses through Security Group, so if someone is not authorized, they cannot touch the machine at all..
 The issue I am running into is that all of the folks that cannot get in simply spin and timeout.  I would like them to get a message "You are not authorized to view this site".  How can I do that before I hit the page?
 I need to be able to check with the users IP address.

Thank you ion advance,
0
Pros and more Cons of using SASS on a new MVC website?

I have not used SASS but hear it produces perfect CSS files. One downside is that everyone who needs to create classes must learn the SASS scripting language. Another may be that debugging time is much higher.

Are there, instead, good coding practices that all developers can follow, so they can avoid the negatives of using SASS and get some of the benefits of using standardized CSS?

(I am not sure if the MVC site will use the Razor View Engine, but does this change your opinion of using SASS?)

Thanks
0
What .NET Technologies in a New MVC Application?

If you needed to architect a new  .NET MVC Application today, what would it consist of?

What version of .NET, MVC, might it be?
And what about Dependency Inversion?
What about Unit Testing?
What is your preferred Unit Test Framework?
What about AutoMapper?
How about a MOQ tool?

And what else am I forgetting to mention?

Thanks
0
Please explain .NET Standard 2.0 and open source.

and how code reuse is enhanced by giving me an example or two of how this is a benefit. For example, a library that can be re-used between various platforms.

And is .NET Standard 2.0 a part of the open sourcing of the .NET Framework? Or is it MVC that is open sourced?
Thanks
0
Difference between URL forwarding and re-routing?

I am curious what the difference is from an MVC .NET Framework perspective, if that makes any difference...

Thanks
0
I'm using Visual Studio 2017 with C#.
I have a method like this.  It's supposed to convert a string to an integer.  If the string does not meet certain conditions there is an exception.
What's the best way to let whatever called this method know the details of the exception?

        public int GetScore(string s)
        {
            try
            {
                int score = 0;
                int totalScore = 0;
                string individualCard = "";
                bool oneJokerFound = false;
                bool twoJokersFound = false;
                int number;
                if (s == null)
                {
                    return 0;
                }
                else if (s == "")
                {
                    return 0;
                }
                for (int i = 2; i < s.Length; i += 3)
                {
                    if (s.Substring(i, 1) != ",")
                    {
                        throw new Exception("Incorrectly formatted string");
                    }
                }
                s = s.Replace(",", "");
                do
                {

}

Open in new window

0
How does ASP.NET – "SameSite Cookie" block XSS attacks?

Please give me a quick view under the covers how this .NET Framework Version 4.7.2 feature helps stop XSS attacks.

And how is it that an MVC site did not have this exposure with earlier versions of .NET Framework?

Thanks
0
Dividing line between .NET Framework and ASP.NET?

When in comes to differentiating between .NET Framework and ASP.NET, I am a bit confused. Here are the list of enhancements to .NET Framework 4.7.1

For example, do the features below, which explicitly mention ASP.NET, only apply to "code behind" kinds of Web Forms?

The .NET Framework 4.7.1 includes improvements in several areas:

Accessibility improvements in narration, high contrast and focus control areas
.NET Framework support for .NET Standard 2.0 and compiler features
More secure SHA-2 support in ASP.NET and System.Messaging
Configuration builders
ASP.NET Execution step feature
ASP.NET HttpCookie parsing

Performance and reliability improvements

Thanks
0
What are the recent enhancements to the .NET Framework since 4.5?

What is the current latest released version? Are there any reasons to NOT use this latest version on a new .NET Framework MVC project?

So, what are the big updates since 4.5? And when was 4.5 released?

Thanks
0
What top .NET Technologies for .NET Technical Lead Role?

I am brushing up on various .NET Technologies to fill a  .NET Technical Lead Role which will involve not only various technology choices, but mainly the communication with a global team of developers who need to implement these technologies.

So, please provide me a list of .NET Technologies which I should prioritize as I spend the next few weeks ramping up.

I may also be looked at to assemble a list of coding standards (coding do's and don't's), then to use code reviews, pull requests, etc. to help communicate those coding standards to a team, some of which may be an offshore and on a different timezone.

So, can you start with a short list of .NET technologies that can prime the pump and get my juices flowing again with these topics, most (or all) I have worked with previously in some capacity.

Thanks.
0
I've been ask this question in two different interviews...

What is the benefit of using stored proc ? another guy asked... when would you use a stored proc over inline sql

My answer:
Stored proc makes an application database agnostic ... application layer is separate from the data
Stored procs are compiled

----
When do we want to use a SP over inline SQL?  I didn't answer this one.

---
No matter how much I prepare for an interview... there's always something unexpected thrown at me!
0
I have the following codes to locate our website visitor's location. and I think the code below is only reading to our server's location.
It works but I do not think this is something we can get web visitor's current location.

My question is:
1. Above statement. do you think it is right?
2. Do you know any ways I can find our website visitor's current location regardless it is on mobile or PC?  I understood there is some proxy or some router may not indicate the current location. That is something I can live with. But I do need some ways to get their location instead of just our server address.



  public static Domain.IpInfo GetCurrentPosition()
        {
            //https://ipinfo.io/developers/replacing-getcurrentposition
            Domain.IpInfo ipInfo = new Domain.IpInfo();
            try
            {
                string info = new WebClient().DownloadString("http://ipinfo.io/geo");
                ipInfo = JsonConvert.DeserializeObject<Domain.IpInfo>(info);

                RegionInfo myRI1 = new RegionInfo(ipInfo.Country);
                ipInfo.Country = myRI1.EnglishName;

                RegionInfo myCity = new RegionInfo(ipInfo.City);
                ipInfo.City = myCity.EnglishName;

                RegionInfo myState = new RegionInfo(ipInfo.Region);
                ipInfo.Region = myState.EnglishName;

                RegionInfo myZip = new RegionInfo(ipInfo.Postal);
                ipInfo.Postal = myZip.EnglishName;

                

Open in new window

0
I've been reading about anonymous types and I think the answer to this question is the 4th one "new class with properties both set and get methods". Saw an explanation on a site but forgot to bookmark it

b3.png
0
Hoping someone can help as I'm totally confused

I'm trying to create 2 similar but not identical XML files

In the code bellow I don't understand

  • Why I can't loop through the first lists I have  to create second lists to print out the name @ ##1

  • Why I get exception errors when trying to use XmlSerializer @##2

  • How do I make the XmlSerializer so I can feed it either list?

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace SplitXML
{
    class Program
    {
        // create two logs to hold each list
        static List<History> HistoryLog = new List<History>();
        static List<DownLoadLog> downloadlog = new List<DownLoadLog>();

        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            // Dummy varibles;

            int myID = 123;
            int FileCount = 234;
            string ModName = "Hello World";
            string OldDir = @"D:\Path\To\OldPath";
            string NewDir = @"D:\Path\To\NewPath";


            // make a loop just   to test
            // this is to simulate where the infomation will be
            // derived from  
            for (int i = 1; i < 5; i++)
            {
                // history log
                History history = new History();

                

Open in new window

0
Practicing interview questions. Why does the second line throws an error? Is it because an explicit conversation is needed? I read about ValueTypes but still don't understand why it errors out..


IEnumerable<object> objects = new List<string>();
IEnumerable<ValueType> v =  objects; //*** error here.
0
I'm reviewing some interview questions. Why is the first one wrong and the second one correct?

            IEnumerable<string> objects1 = new List<object>(); //*** not correct

            IEnumerable<object> objects = new List<string>(); //correct
0
I had an interview the other day and they let me keep the test. I'm reviewing it to learn more...

One of the questions is: difference between  declaring an argument as "dynamic" vs "object". I answered #2 below. I've been reading about it and I think it's correct because of boxing and unboxing --> dynamic doesn't need it but Object can be cast. Is this correct?

b1.png
0
Hello EE,

I need to count the days intervals in a dictionnary Of(Date, String)

so if row 1 is :     12/01/01/2019,  ABC
row 2 is :   12/01/15/2019, XYZ
row 3 is : 12/02/22/2019, MNP


I need to have results like this somehow:  

15 days
38 days


so there is 15 days interval between row1 and row2 and there is 38 days between dates of row and row 3  (we need also to take into account the 30/31/28 ending days of months)

how can I do that!? Any efficiant ways with LINQ maybe ?
0
I have a website and try to track client IP to locate his/her for better information tracking.
we use c#/mvc/razor.

any suggestions on what we can use?

Thanks
0
i use @HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) but it does not read https. it read http only. how to fix it?
0
Hi,
Thanks!
This is regarding sonarqube complaint. I am using

public async Task<(Guid, string, Guid)> GetAllCategories()
{
    return (Guid.Parse(data["Id"].ToString()),
            data["StatusName"].ToString(),
            Guid.Parse(data["StatusId"].ToString())
    );
}

Open in new window


Sonarqube is complaining "Remove this return statement or make it conditional" . Please help me how to fix this bug..

Kind regards,
Pooja
0
I'm using Visual Studio 2017 with C#.
I want a user to input some letters into a textbox.  A model maps each letter to a number and returns the total.  how can I display the result (Total variable in the model) in a text area in the same view?

Home Controller
public ActionResult Cards()
        {
            return View();
        }
        public ActionResult Cards(CardModel C)
        {
            C.GetScore(C.Deck);
            return View();
        }

Open in new window


Cards View
@{
    ViewBag.Title = "Cards";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<h2>Cards</h2>

    <h2>Please enter a number</h2>

      First name: <input type="text" name="Deck"><br>
      <textarea id="TextArea1" rows="2" cols="20"></textarea>
    <input type="submit" value="Submit">

Open in new window


Model
 public class CardModel
    {
        public string Deck { get; set; }
        public int GetScore(string s)
        {
            int score = 0;
            int totalScore = 0;
            string individualCard = "";
            //loop through each letter in string and convert to a number.
           return Total
}
}

Open in new window

1
I'm practicing some online code examples for my potential interviews and I came across one code sample --> pass in 2 integers and bring back odd numbers between the range, inclusive.

Why is this bringing back 11? it shouldn't

Or, if I pass 96 and 97

List<int> list = new List<int>();

			int l = 3;
			int r = 9;

			List<int> t = Enumerable.Range(l, r).ToList();
			var oddNumbers = t.Where(num => num % 2 != 0);

			foreach (int i in oddNumbers)
				list.Add(i);

			var res = list;

Open in new window

0

C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).